I am unable to set cookies in vercel app for my application. While my backend is deployed in render.
- Dominant language
- JavaScript
- Stars
- 69.5k
- Forks
- 25k
- Avg merge
- 4d 20h
- Merged PRs (30d)
- 9
Description
@AtuI-Yadav @Rudra-Sankha-Sinhamahapatra But it also does not work for me. Have Any Solution?
Here is my backend api code **deployed on render**:
```
const isProd = process.env.NODE_ENV === "production";
const apiDomain=process.env.API_URL?.split("//")[1]; //it return skillhub-backend-xyz.onrender.com
//setting token
res.cookie("token", token, {
httpOnly: true,
secure: isProd ? true : false, // true only on HTTPS
sameSite: isProd ? "none" : "lax", // none for production, lax for localhost
maxAge: 7 * 24 * 60 * 60 * 1000, //7 days
domain: isProd ? apiDomain :"localhost"
});
```
and here is my **backend cors policy:**
```
// Global middleware
app.use(cors({
origin: process.env.CLIENT_URL || "*", // it return the frontend URL https://skill-xyz.vercel.app
methods: ["GET", "POST", "PUT", "DELETE"],
credentials: true,
}));
```
Here is my **frontend code deployed on vercel:**
```
//here my env var for NEXT_PUBLIC_API_URL=https://skillhub-backend-xyz.onrender.com/api
const API_URL = `${process.env.NEXT_PUBLIC_API_URL}/auth`;
const res = await fetch(`${API_URL}/login`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ email, password }),
credentials: "include",
});
const data = await res.json();
if (!res.ok) throw new Error(data.message || "Login failed");
setMessage("Login successful!");
```
I want to mention that It work fine at localhost and in production when **I test via Postman**, render also setting cookies in postman returned cookies. But in vercel, when i login from my frontend url, it does not set cookies..
_Originally posted by @rajgupta2 in https://github.com/expressjs/express/discussions/5423#discussioncomment-15110258_
Contributor guide
Assessment
This issue has not been assessed yet.