Hi, im implementing SuperTokens in a NextJS app (w...
# support-questions-legacy
n
Hi, im implementing SuperTokens in a NextJS app (with an external NodeJS API) using the ThirdPartyEmailPassword recipe. Everything is working fine, but I was expecting the user info to be present in the session object. Is there a way to add properties to the user context in client-side ? I need the user’s email, but the session only returns the id.
r
hey @nip10 You need to override the createNewSession on the backend and add the email of the user in the access token payload.
n
thanks @rp_st ,I was able to make it work!
do you have any docs on how to type the accesstokenpayload using typescript ? similiar to next-auth
r
im not sure what you mean here. the type of accesstokenpayload is just a JSON object
n
similar to this https://next-auth.js.org/getting-started/typescript#module-augmentation because you can add any property to the payload, it would be nice to be able to augument that specific type in the front-end
so i can restrict the type of the payload to match the properties that I am adding in the backend so imagine i do this on the backend
Copy code
ts
input.accessTokenPayload = {
   ...input.accessTokenPayload,
  extraProperty: "hello world",
};
i would do something like this on the frontend types.d.ts
Copy code
ts
interface AccessTokenPayload {
  extraProperty: string
} & DefaultAccessTokenPayload
r
right. Thats not there at the moment per se. You can open an issue about this. In the meantime, you can do something like this on the frontend though:
Copy code
ts
interface AccessTokenPayload {
  extraProperty: string
}

let accessTokenPayload: AccessTokenPayload = await session.getAccessTokenPayloadSecurely()
n
ok got it!
in what repo should i open the issue ? react ?
r
supertokens-website
n
another related question @rp_st I can add properties to the userContext before signin using
input.userContext.myProperty
but this approach doesn't work after the signin (because we already called the original impl fn). I found
mergeIntoAccessTokenPayload
and it seems to work, is this the correct way to do this ? snippet for reference
Copy code
ts
emailPasswordSignInPOST: async function (input) {
  if (originalImplementation.emailPasswordSignInPOST === undefined) {
    throw Error("Should never come here");
  }
  input.userContext.propertyPreSignIn = "pre sign in";
  let response = await originalImplementation.emailPasswordSignInPOST(input);
  if (response.status === "OK") {
    // Do some stuff after sign in, get values from the database that we want to add to the access token payload
    input.userContext.ignoredProperty = "doesnt work because we already called the originalImpl fn";
    // console.log("[E+P] POST SIGN IN LOGIC", input, response);
    await response.session.mergeIntoAccessTokenPayload({
propertyPostSignIn: "post sign in - value from database after status OK" });
  }
  return response;
},
r
this works, yea.
2 Views