Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Session error #4

Open
RoskiDeluge opened this issue Feb 24, 2022 · 4 comments
Open

Session error #4

RoskiDeluge opened this issue Feb 24, 2022 · 4 comments

Comments

@RoskiDeluge
Copy link

RoskiDeluge commented Feb 24, 2022

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.

@khristos
Copy link

khristos commented Feb 28, 2022

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"
},

tomaskebrle pushed a commit to tomaskebrle/build-a-saas-with-next-js-supabase-and-stripe that referenced this issue Mar 5, 2022
It seems that supabase updated the way it sends cookies, and the code doesn't, this results in 500 error. Resolves dijonmusters#4
@stoplion
Copy link

Same. Is the correct way like this?

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

@khristos
Copy link

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

@sdbxsdb
Copy link

sdbxsdb commented Sep 16, 2022

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants