build-a-saas-with-next-js-supabase-and-stripe icon indicating copy to clipboard operation
build-a-saas-with-next-js-supabase-and-stripe copied to clipboard

Session error

Open RoskiDeluge opened this issue 3 years ago • 4 comments

Hi. I'm unable to move past lesson #19. I followed along and adjusted the code in [priceId].js to pass the session token to supabase, but I'm still receiving the 500 type error: "cannot read property 'stripe_customer' of null"

I'm not sure how to proceed. Should the server side call be handled differently?

For context, my code was working fine up to this point. So I'm confident the issue can be narrowed down to how the session cookie is being dealt with between Next and Supabase.

RoskiDeluge avatar Feb 24 '22 19:02 RoskiDeluge

I had a similar issue as well.

*** TypeError: Cannot read properties of null (reading 'stripe_customer') *** *** Status Code: 500 Internal Server Error ***

FILE: /pages/api/subscription/[priceId].js

ORIGINAL: const token = cookie.parse(req.headers.cookie)["sb:token"];

CORRECTED: const token = cookie.parse(req.headers.cookie)["sb-access-token"];

VERSIONS: "dependencies": { "@supabase/supabase-js": "^1.30.3", "axios": "^0.26.0", "cookie": "^0.4.2", "next": "^12.0.10", "react": "^17.0.2", "react-dom": "^17.0.2", "react-player": "^2.9.0", "stripe": "^8.203.0" },

khristos avatar Feb 28 '22 05:02 khristos

Same. Is the correct way like this?

supabase.auth.session = () => ({
    access_token: token,
    token_type: 'Bearer',
    user
  });

stoplion avatar May 12 '22 03:05 stoplion

Kendy205 provided a link to a PULL REQUEST that incorporates the fix that worked for me, i.e. the name of the cookie changed.

khristos avatar May 12 '22 12:05 khristos

Is there any update on this? I'm getting an AxiosError:

my-crew:1 Uncaught (in promise) AxiosError {message: 'Request failed with status code 500', name: 'AxiosError', code: 'ERR_BAD_RESPONSE', config: {…}, request: XMLHttpRequest, …}

and

| const handler = async (req, res) => {
> 4 |   await supabase.auth.api.setAuthCookie(req, res);
    |        ^
  5 |   console.log(req);
  6 | };

error - TypeError: Cannot read property 'setAuthCookie' of undefined at handler (webpack-internal:///(api)/./pages/api/set-supabase-cookie.js:8:80)

sdbxsdb avatar Sep 16 '22 10:09 sdbxsdb