https://supertokens.com/ logo
Title
f

funk101

11/29/2022, 7:53 PM
NextJS/React - My site uses Stripe checkout session. It basically leaves, goes through Stripe payment flow and sends a webhook(server code) back. At that point I need to access the SuperTokens session, or accessTokenPayload. Can you point in the direction.
r

rp

11/30/2022, 3:47 AM
Hey @funk101
If you have the user Id of that user then you can get their access token payload from their session
f

funk101

11/30/2022, 3:52 AM
this code uses typescript
export default async function myApi(req: SessionRequest, res: any) {
r

rp

11/30/2022, 3:53 AM
Yea. Just remove the types and it should be fine with js
f

funk101

11/30/2022, 3:53 AM
you mean (req, res) ?
r

rp

11/30/2022, 3:53 AM
No. The types
“: SessionRequest” part
And “: any” part
f

funk101

11/30/2022, 3:54 AM
right, I just pass in (req, and res)
r

rp

11/30/2022, 3:54 AM
Yes
f

funk101

11/30/2022, 3:56 AM
yeah, bare with me, I've tried this but I have param coming in as well
export default async function updateMemberCustomerId(customerId, req, res) {
  await superTokensNextWrapper(
    async (next) => {
      await verifySession()(req, res, next);
    },
    req,
    res
  );
  let session = req.session;

  let accessTokenPayload = session.getAccessTokenPayload();

  
  const values = [customerId, userId];
  const q = "update members set stripe_customer_id=? where supertokens_id=?";
  console.log("Query: ", q, values);

  try {
    const result = await query(q, values);
    return result;
  } catch (err) {
    const errMsg = err.message || err;
    serverLogger.error("/update-member-customer_id", errMsg);
    return errMsg;
  }
}
updateMemberCustomerId(id);
that's the call coming from another page, so there's no 'req, res` being passed I guess I don't get how that could work, not your problem though I guess
r

rp

11/30/2022, 3:58 AM
In the pages I sent you, see offline mode section
You can get the user’s access token payload with their sessionHandle
Without req and res
f

funk101

11/30/2022, 3:58 AM
thanks
Yeah, can't be offline mode cause I don't have the supertokens id, that's what I need to get, oh well I'll see if I can figure this out
r

rp

11/30/2022, 4:06 AM
You don’t even have the userId?
f

funk101

11/30/2022, 4:07 AM
I have it until I go through the stripe checkout flow. the stripe sends a webhook which is server side at that point I need to update the db, and then stripe sends the user back to my server. of course then I can pick up the supertokens session, make sense?
I can access session before and after the STripe work flow
make sense?
let me dig in
r

rp

11/30/2022, 4:14 AM
Alright
f

funk101

11/30/2022, 4:48 AM
look, here's the handler
export default async function handler(req, res) {
  const event = req.body;

  await superTokensNextWrapper(
    async (next) => {
      await verifySession()(req, res, next);
    },
    req,
    res
  );

  let userId = req.session.getUserId();
the (req, res) is for Stripe sending the event. So I can't use that for the req.session.getUserId(). See? Is there another way? I can't use frontend logic
r

rp

11/30/2022, 4:49 AM
You can’t.
f

funk101

11/30/2022, 4:49 AM
but it is server code
r

rp

11/30/2022, 4:50 AM
You will need to make stripe return the userId somehow. Ask them please
f

funk101

11/30/2022, 4:50 AM
ok, thanks
r

rp

11/30/2022, 4:50 AM
They may have some state variable or something. Not sure
f

funk101

11/30/2022, 4:51 AM
I think I need to do this on the next page, no worries, thanks for "being there"