https://supertokens.com/ logo
adding info to access token payload
m

miguelstevensbe

04/16/2023, 3:56 PM
Hi everyone! How can I get the user's data on the frontend? I'm trying to use
let accessTokenPayload = await Session.getAccessTokenPayloadSecurely();
But this only returns the following: "accessTokenPayload": { "st-ev": { "v": true, "t": 1681660514888 } }
r

rp

04/16/2023, 3:59 PM
you need to override the createNewSession function on the backend to add whatever info you like into the access token payload. See this: https://supertokens.com/docs/session/common-customizations/sessions/claims/access-token-payload
m

miguelstevensbe

04/16/2023, 4:00 PM
Thanks @rp ! I'm looking at the docs, so the e-mail address can be fetched from that input variable in the example?
r

rp

04/16/2023, 4:01 PM
the input var has the user id which u can use to get the email
m

miguelstevensbe

04/16/2023, 4:04 PM
Aha, it seems to work using
let userInfo = await EmailPassword.getUserById(userId)
. Is it possible to store a user's name in there as well? During signup etc?
r

rp

04/16/2023, 4:17 PM
Yea. You can store anything
m

miguelstevensbe

04/16/2023, 4:26 PM
Great! Thanks for the fast response! You guys are amazing!
@rp do I need to use the UserMetadata for this to work?
I would like to user the first_name and last_name fields
r

rp

04/17/2023, 5:44 AM
you don't need to use the user metadata recipe, but it would be an appropriate use of it indeed. You can override the sign up function in override.functions (not override.apis), and then add to the user metadata recipe in your override. You can then read from the user metadata recipe in createNewSession override to get the name and add it to the access token payload.
m

miguelstevensbe

04/17/2023, 11:35 AM
Great! That's working, thanks