https://supertokens.com/ logo
f

funk101

06/05/2022, 2:56 PM
I'm trying to store other information in the session and make it available. Will this be available in useSessionContext() ?
r

rp

06/05/2022, 2:57 PM
hey!
Yea. That goes in the backendConfig indeed
Also, if you store info in the
accessTokenPayload
, that will be available on the frontend when you do
useSessionContext
f

funk101

06/05/2022, 2:58 PM
can I show you my backendConfig() logic?
r

rp

06/05/2022, 2:58 PM
yea sure
f

funk101

06/05/2022, 2:58 PM
partial:
Copy code
override: {
          apis: (originalImplementation) => {
            return {
              ...originalImplementation,
              signUpPOST: async function (input) {
                if (originalImplementation.signUpPOST === undefined) {
                  throw Error("Shouldn't come here");
                }
                try {
                  const response = await originalImplementation.signUpPOST(
                    input
                  );
                  if (response.status === "OK") {
                    const formFields = input.formFields;
                    formFields.push({
                      id: "userId",
                      value: response.session.userId,
                    });
                    addUser(formFields);
                  }
                  return response;
                } catch (err) {
                  serverLogger.error("/config/backendConfig: ", err.message);
                }
              },
            };
          },
          functions: (originalImplementation) => {
            return {
              ...originalImplementation,
              createNewSession: async function (input) {
                let userId = input.userId;
                // accessible to frontend
                input.accessTokenPayload = {
                  ...input.accessTokenPayload,
                  stripeSellerId: "hello world",
                };
                input.sessionData = {
                  ...input.sessionData,
                  stripeSellerId: "hello world",
                };
                return originalImplementation.createNewSession(input);
              },
            };
          },
        },
      }),
      SessionNode.init(),
r

rp

06/05/2022, 2:59 PM
Can you format it correctly please?
this is quite hard to consume
use
Copy code
this style code snippets
f

funk101

06/05/2022, 3:00 PM
I wrap it in backticks, right? single?
r

rp

06/05/2022, 3:00 PM
Yea. three backticks (can google this)
f

funk101

06/05/2022, 3:00 PM
Copy code
override: {
          apis: (originalImplementation) => {
            return {
              ...originalImplementation,
              signUpPOST: async function (input) {
                if (originalImplementation.signUpPOST === undefined) {
                  throw Error("Shouldn't come here");
                }
                try {
                  const response = await originalImplementation.signUpPOST(
                    input
                  );
                  if (response.status === "OK") {
                    const formFields = input.formFields;
                    formFields.push({
                      id: "userId",
                      value: response.session.userId,
                    });
                    addUser(formFields);
                  }
                  return response;
                } catch (err) {
                  serverLogger.error("/config/backendConfig: ", err.message);
                }
              },
            };
          },
          functions: (originalImplementation) => {
            return {
              ...originalImplementation,
              createNewSession: async function (input) {
                let userId = input.userId;
                // accessible to frontend
                input.accessTokenPayload = {
                  ...input.accessTokenPayload,
                  stripeSellerId: "hello world",
                };
                input.sessionData = {
                  ...input.sessionData,
                  stripeSellerId: "hello world",
                };
                return originalImplementation.createNewSession(input);
              },
            };
          },
        },
      }),
      SessionNode.init(),
better?
r

rp

06/05/2022, 3:00 PM
thanks
So yea, the stuff that goes in
accessTokenPayload
will be accessible on the frontend via
useSessionContext
So if you are saving
stripeSellerId
in
accessTokenPayload
, you don't need to save it in
sessionData
.
f

funk101

06/05/2022, 3:02 PM
so that should work? cause when I do
Copy code
console.log(useSessionContext())
it's not there
Copy code
accessTokenPayload:
[[Prototype]]: Object
doesSessionExist: true
userId: "c3af1584-6d65-43fd-804e-de299f1ccb8a"
that's me console.log
r

rp

06/05/2022, 3:04 PM
Can you do:
Copy code
const { accessTokenPayload, userId } = useSessionContext()

console.log(accessTokenPayload)
console.log(userId)
f

funk101

06/05/2022, 3:06 PM
Copy code
{}
c3af1584-6d65-43fd-804e-de299f1ccb8a
r

rp

06/05/2022, 3:06 PM
hmm. Can you logout and login again?
f

funk101

06/05/2022, 3:06 PM
same
r

rp

06/05/2022, 3:06 PM
Also, if you can see the cookie store on your browser and send the value of
sFrontToken
f

funk101

06/05/2022, 3:07 PM
tes
yes
eyJ1aWQiOiJjM2FmMTU4NC02ZDY1LTQzZmQtODA0ZS1kZTI5OWYxY2NiOGEiLCJhdGUiOjE2NTQ0NDUyMDI5MDQsInVwIjp7fX0=
r

rp

06/05/2022, 3:08 PM
hmm
Can you add a print statement in the
createNewSession
function on the backend?
And see if that gets printed out
when you login
f

funk101

06/05/2022, 3:10 PM
you mean console.log(input.accessTokenPayload) ?
r

rp

06/05/2022, 3:10 PM
yea sure. right before you run
return originalImplementation.createNewSession(input);
f

funk101

06/05/2022, 3:10 PM
ok
not showing
hmm
r

rp

06/05/2022, 3:11 PM
clear cache, delete the
.next
folder, rebuild and try again
nextjs does this sometimes
f

funk101

06/05/2022, 3:16 PM
please hold...
hmm, same
I mean, no output
r

rp

06/05/2022, 3:31 PM
Can you make some change like not calling supertokens.init on the backend at all and seeing if things break?
Cause it’s most likely a caching issue
f

funk101

06/05/2022, 3:34 PM
should I remove the sIRTFrontend cookie?
yeah, no errors when I remove supertokens: {}
r

rp

06/05/2022, 3:38 PM
Right. So some caching issue for sure
Please make sure your updates are getting pushed properly.
Nope.
f

funk101

06/05/2022, 3:39 PM
I'll deal with this, I have to run out a second, can I leave this message thread open?
r

rp

06/05/2022, 3:40 PM
Sure.
f

funk101

06/05/2022, 3:40 PM
thanks
man this is crazy
r

rp

06/05/2022, 5:26 PM
Why so?
f

funk101

06/05/2022, 5:27 PM
cleared cache, wasted .next folder, using incognito and still seeing something other than my code, which is localhost, no git
r

rp

06/05/2022, 5:27 PM
That’s very weird. 😅
f

funk101

06/05/2022, 5:31 PM
ok, I had to waste the cookies, and it busted cause I commented out appInfo
r

rp

06/05/2022, 5:31 PM
Hmm
f

funk101

06/05/2022, 5:31 PM
however, now still not seeing my
Copy code
console.log("stripeSellerId: ", input.accessTokenPayload);
looks like it's not reading that "functions override" code
r

rp

06/05/2022, 5:34 PM
Oh right. The create new session function is in the session recipe
You have given it in the wrong recipe
f

funk101

06/05/2022, 5:35 PM
ah
so i put it in here -> SessionNode.init(),
r

rp

06/05/2022, 5:36 PM
Yes
Only the createNewSession override stuff
f

funk101

06/05/2022, 5:37 PM
right
and that only happens during signin, right?
r

rp

06/05/2022, 5:37 PM
And signup
f

funk101

06/05/2022, 5:40 PM
woot! now I see it.
r

rp

06/05/2022, 5:40 PM
Great!
f

funk101

06/05/2022, 5:40 PM
so, I can't update the data in this session?
r

rp

06/05/2022, 5:40 PM
You can
After session verification, you can do session.updateAccessTokenPayload(..)
In any API
and that will update the session info
f

funk101

06/05/2022, 5:41 PM
ok, and then just pass {key: value}
r

rp

06/05/2022, 5:41 PM
Yea.
See the function signature. I don’t recall of the top of my head
f

funk101

06/05/2022, 5:41 PM
ok, thanks