I'm trying to store other information in the sessi...
# support-questions
f
I'm trying to store other information in the session and make it available. Will this be available in useSessionContext() ?
r
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
can I show you my backendConfig() logic?
r
yea sure
f
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
Can you format it correctly please?
this is quite hard to consume
use
Copy code
this style code snippets
f
I wrap it in backticks, right? single?
r
Yea. three backticks (can google this)
f
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
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
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
Can you do:
Copy code
const { accessTokenPayload, userId } = useSessionContext()

console.log(accessTokenPayload)
console.log(userId)
f
Copy code
{}
c3af1584-6d65-43fd-804e-de299f1ccb8a
r
hmm. Can you logout and login again?
f
same
r
Also, if you can see the cookie store on your browser and send the value of
sFrontToken
f
tes
yes
eyJ1aWQiOiJjM2FmMTU4NC02ZDY1LTQzZmQtODA0ZS1kZTI5OWYxY2NiOGEiLCJhdGUiOjE2NTQ0NDUyMDI5MDQsInVwIjp7fX0=
r
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
you mean console.log(input.accessTokenPayload) ?
r
yea sure. right before you run
return originalImplementation.createNewSession(input);
f
ok
not showing
hmm
r
clear cache, delete the
.next
folder, rebuild and try again
nextjs does this sometimes
f
please hold...
hmm, same
I mean, no output
r
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
should I remove the sIRTFrontend cookie?
yeah, no errors when I remove supertokens: {}
r
Right. So some caching issue for sure
Please make sure your updates are getting pushed properly.
Nope.
f
I'll deal with this, I have to run out a second, can I leave this message thread open?
r
Sure.
f
thanks
man this is crazy
r
Why so?
f
cleared cache, wasted .next folder, using incognito and still seeing something other than my code, which is localhost, no git
r
That’s very weird. 😅
f
ok, I had to waste the cookies, and it busted cause I commented out appInfo
r
Hmm
f
however, now still not seeing my
Copy code
console.log("stripeSellerId: ", input.accessTokenPayload);
looks like it's not reading that "functions override" code
r
Oh right. The create new session function is in the session recipe
You have given it in the wrong recipe
f
ah
so i put it in here -> SessionNode.init(),
r
Yes
Only the createNewSession override stuff
f
right
and that only happens during signin, right?
r
And signup
f
woot! now I see it.
r
Great!
f
so, I can't update the data in this session?
r
You can
After session verification, you can do session.updateAccessTokenPayload(..)
In any API
and that will update the session info
f
ok, and then just pass {key: value}
r
Yea.
See the function signature. I don’t recall of the top of my head
f
ok, thanks