build-a-saas-with-next-js-supabase-and-stripe
build-a-saas-with-next-js-supabase-and-stripe copied to clipboard
Session error
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.
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" },
Same. Is the correct way like this?
supabase.auth.session = () => ({
access_token: token,
token_type: 'Bearer',
user
});
Kendy205 provided a link to a PULL REQUEST that incorporates the fix that worked for me, i.e. the name of the cookie changed.
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)