Hi everyone! How can I get the user's data on the ...
# support-questions-legacy
m
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
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
Thanks @rp_st ! I'm looking at the docs, so the e-mail address can be fetched from that input variable in the example?
r
the input var has the user id which u can use to get the email
m
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
Yea. You can store anything
m
Great! Thanks for the fast response! You guys are amazing!
@rp_st do I need to use the UserMetadata for this to work?
I would like to user the first_name and last_name fields
r
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
Great! That's working, thanks
6 Views