https://supertokens.com/ logo
tenant id in access token
w

whatsappx-thomas

03/30/2023, 10:52 PM
I need to store a
tenantId
information on my user (like, to which organisation he belongs). I am currently doing this via the metadata. Everything is fine there. I am not really happy because I need to make a separate request just to get that info. I need to check that my
current_user
really has access to the tenant he's trying to reach. How can I avoid a second request just to get a basic info ?
r

rp

03/31/2023, 6:24 AM
hey @whatsappx-thomas you can store the tenant id in user metadata, and then you can override the createNewSession function and read the tenant id from the user metadata and put it in the access token payload. From there on, you can read the tenant id from the session's access token payload directly on the frontend and in your apis
d

Davido

04/01/2023, 12:11 AM
Is the metadata available in createNewSession while the account is being created? I'm debugging this now as this info seems to be null until logout/in.
r

rp

04/01/2023, 5:26 AM
are you adding the metadata in the apis override or in functions override? In the apis override, when you call the original implementation, that internally calls the function override and then the createNewSession before returning. So if you want to do something before createNewSession, you should add that logic in the function override
w

whatsappx-thomas

04/12/2023, 1:07 PM
@rp can you pinpoint me some doc on how to override the createNewSession function ? Can't find it on the SuperTokens doc
There is something I don't understand though: How can I have access to the metadata in the
createNewSession
?
r

rp

04/12/2023, 2:50 PM
yup!
> How can I have access to the metadata in the createNewSession ? You have the user ID as an input tot he createNewSession function. You can query the user metadata recipe with the userId to get info about the user. You can even query your own db if you like.