NextJS/React - My site uses Stripe checkout sessio...
# general
f
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
Hey @funk101
If you have the user Id of that user then you can get their access token payload from their session
f
this code uses typescript
Copy code
export default async function myApi(req: SessionRequest, res: any) {
r
Yea. Just remove the types and it should be fine with js
f
you mean (req, res) ?
r
No. The types
“: SessionRequest” part
And “: any” part
f
right, I just pass in (req, and res)
r
Yes
f
yeah, bare with me, I've tried this but I have param coming in as well
Copy code
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;
  }
}
Copy code
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
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
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
You don’t even have the userId?
f
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
Alright
f
look, here's the handler
Copy code
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
You can’t.
f
but it is server code
r
You will need to make stripe return the userId somehow. Ask them please
f
ok, thanks
r
They may have some state variable or something. Not sure
f
I think I need to do this on the next page, no worries, thanks for "being there"
2 Views