What is the method to get user id from accessToken...
# support-questions-legacy
m
What is the method to get user id from accessTokenPayload? couldn't find any method here: https://supertokens.com/docs/nodejs/modules/recipe_session.html
r
Hey @monish.chhadwa
The access token payload only contains the custom claims
The session container object (which is the result of verifySession) has session.getUserId()
m
Hey @rp_st this I understood But we are implementing the guest user flow..and we want to transfer the guest session data to the signed in session. In this case, we will have the normal signed in user(the user id for which we will get via the verifySession method). But we will also have the previous access token for the guest user; how do I get session data from this access token?
r
Right. So you can call the getSession function with the request object and that should verify the guest access token and give you bad the session object for the guest session
Then you can use session.getUserId on that
m
Okay and I add the guest token as a header in the request object?
So: 1. The incoming request object has access token of the signed in user. This will be used in the verifySession method by default 2. I temporarily override the request object with guest access token and get its details 3. And then I re-substitute the original access token in the request object
r
How does the incoming request have the signed in user’s session? Don’t you transfer all the data when the user logs in?
m
No, we can't transfer all the data when user logs in...the user has to perform additional steps after logging in...and till then the client stores the guest access token
r
Ah I see. Do you care about verifying the guest access token?
Or just want the user id from it?
m
I just want the user id from it
r
Right. So you can base64 decode and then json parse the payload part of it and there should be a userId field
m
Okay cool, let me try that!
I have missed something here.. It doesn't seem to be working for me

https://cdn.discordapp.com/attachments/1099584491250516000/1099597499443986432/Screenshot_2023-04-23_at_12.57.11_PM.png

https://cdn.discordapp.com/attachments/1099584491250516000/1099597499724996618/Screenshot_2023-04-23_at_12.57.02_PM.png

I copied the accessToken part and tried to base64 decode the same
r
So split it using the “.” And take the second element (index 1) of the splitted array
And try the base 64 decode on that
m
Okay I got it now; but if this isn't a part of some exposed function, then there are chances of it breaking in the future right?
r
Yes. But that will be a breaking change from the SDK version point of view. So you will not get the change automatically
m
Okay cool
Thanks for the info and quick help
Are there any plans of adding such a function in the future though?
r
Yes. Very soon (in a few weeks)
m
Great; where can I know about that update?
r
New-release channel on our discord
3 Views