I am trying to use nodejs sdk but there’s no API for getting logged user info - like email or name
Hello @mtwn105 while we don’t provide an endpoint to get that information directly, there’s a way to do it
If you use Hosted Auth to create a grant for a user, you can get the id_token parameter and simple base64 decode it.
If you follow this Quickstart guide Email API Quickstart: read and send email messages | Nylas Docs on the Receive a callback from Nylas with the user’s grant ID section you will need to get the id_token from the response variable. This variable is long so you will need a little regex to get just the part that you need…
^[^.]+
When you base64 decode that, you will have something like this:
{"alg":"HS256","typ":"JWT"}{"at_hash":"xxx","aud":"https://api.us.nylas.com/v3","email":"xxx@gmail.com","exp":1723894869,"family_name":"Tejada","given_name":"Alvaro","iat":xxx,"iss":"https://nylas.com","name":"Alvaro Tejada","picture":"https://lh3.googleusercontent.com/a/xxx","provider":"google","sub":"xxx-xxx-xxx-xxx-xxx"}
Hi @Blag
Your solution did not work for me, but I was able to decode the idToken
by making an SDK call with auth.idTokenInfo(idToken)
.
Below is an example of what I got with a Gmail connected account. Can you please advise if this output data structure is universal across all providers and I’m safe to query for name
in it, or is it different depending on the provider?
{
requestId: '6116709434-fdae41d8-4cbd-48d1-b6b2-9efba6e5e720',
data: {
iss: 'https://nylas.com',
aud: 'https://api.eu.nylas.com/v3',
sub: '<sub>',
email: '<email>',
atHash: '<hash>',
iat: 1732108866,
exp: 1732112466,
name: '<name>',
givenName: '<name>',
picture: '<pic>'
}
}