Unable to get session from cookie in nextjs serverless function when redirected from another nextjs app using redirect. #50027
Replies: 2 comments 2 replies
-
|
Hi, are you using this library: https://github.com/auth0/nextjs-auth0 ? |
Beta Was this translation helpful? Give feedback.
-
|
Hi @swarnava - I've just tested this locally with 2 applications on different ports with the latest version of Next.js and confirmed that Next.js attaches the cookie to the request to the backend server and the backend application is able to read the session using I just had to make sure that the I can't see anything wrong with the code you've shared, but happy to take a look if you can share an example repo that demonstrates the issue. Also, I see it works on Netlify and not on Vercel, does the same code work on localhost (Running both your frontend app and backend app on different ports)? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
I have both frontend and backend Next.js applications hosted on Vercel. In the frontend app, all API requests are redirected to the backend using the next.config.js file:
However, in the backend server, when attempting to retrieve the session using AuthInstance.getSession(req, res), it returns null and responds with a 401 error.
Since I can successfully retrieve the cookie in getServerSideProps, it appears that there is no issue with the cookie itself.
Are there any additional configurations I need to make in order to properly redirect the request with the cookie? This same setup works flawlessly on Netlify. I am using Auth0 for authentication.
Additional information
Getting the session from serverless backend:
session = AuthInstance.getSession(req, res)Beta Was this translation helpful? Give feedback.
All reactions