Why the req.user is undefined at the production level. Can anyone resolve this issue. I have deploy the frontend on vercel and backend on onrender. #177931
Unanswered
OmkarArdekar12
asked this question in
Projects and Issues
Replies: 1 comment 1 reply
-
|
@OmkarArdekar12 , In production your session cookie isn’t surviving the round-trip, so Passport can’t rehydrate the session and req.user ends up undefined. This is usually a mix of cookie flags, proxy trust, and frontend credentials. You can fix like so: Backend, you can tell Express you’re behind one proxy and tell express-session to honor it: Frontend, send cookies on cross-site requests: Axios (global):
or per-request: |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Select Topic Area
Question
Feature Area
Issues
Body
Why the req.user is undefined at the production level. Can anyone resolve this issue. I have deploy the frontend on vercel and backend on onrender. I am using the 2FA login system. For login the passportjs local strategy and for verification jwt token based authentication.
At the development level everything works fine. But when the backend is deploy on onrender, req.user is not staying persistent.
This is my Code:
index.js file:
passportConfig file:
authRoutes.js file:
Guidelines
Beta Was this translation helpful? Give feedback.
All reactions