When Run frontend and backend in diff domain it not working #1038
Replies: 2 comments
-
You need to change this to your domain. Otherwise, the cookie will not be set and naturally it will seem like no session was created. |
Beta Was this translation helpful? Give feedback.
-
Hey @AsrarMemon! app.use(cors({
origin: `${ process.env.CLIENT_URL }`,
credentials: true,
}));
app.use(session({
name: 'GitHubConnect.sid',
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: false,
cookie: {
domain: process.env.COOKIE_DOMAIN,
maxAge: 1000 * 60 * 60 * 24,
secure: true,
httpOnly: true,
}
}));
app.use((req, res, next) => {
res.setHeader("Access-Control-Allow-Origin", process.env.CLIENT_URL);
next();
}) But, I came to an understanding that this works only for projects that are deployed at a single origin. Apparently, we cannot set cookies in cross-origin deployed projects. Hence, I recommend you to choose other methods such as token-based authentication - JWT. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
When I run Frontend and backend on localhost it working
But When I put this backend code on server and try to call from frontend it is always retune first time
I have already tried with credentials, sameSite all options
but nothing work for me
Your help would be great for me, Already opened issue on slack as well not reply received
Beta Was this translation helpful? Give feedback.
All reactions