New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can not send cookie back from client, tried many ways #4907
Comments
Yes, it is not working. [Edit]: |
thanks, you helped alot |
both of you helped, thank you both |
thanks for this it worked, i missed to add |
IT WORKED! Why did it take me so long to find this?!! |
// middlewares this is servers.js file. const googleAuth = async (req, res, next) => {
} catch (error) { module.exports = { const protect = async (req, res, next) => {
} catch (error) { module.exports = protect; |
Mine works fine in development stage but does not set cookie in production. |
In production I got the same issue. The cookie was not set by the browser, I tryed a lot of possible solutions but what solve my problem was change the domain name. I deployed my API as server.mydomain.com and my frontend was anotherdomain.app and CORS was properly configured. I was able to send request to 'open' routes, but when I tried to login the cookie was ignored by the browser. So, when I changed the frontend to mydomain.com the cookie was set perfectly. |
@willyanbertolino Thanks for your solution. It took me whole day to figure out, but the change in domain name solved my problem. Thank you so much. |
Tried everything but still not working any help`app.post("/api/auth/login", cors(corsOptions), (req, res) => {
}); |
You hadn't provided cookie options in cookie method. Refer following blog. |
Help Plz, in localhost its storing cookies in browser but in deployment it do not and also using plz help!!! |
Check If your cookie is configured right.
I set It as {httpOnly:true, sameSite : 'strict', signed: true}
Em qua, 19 de jul de 2023 15:21, Gaurav Gupta ***@***.***>
escreveu:
… In production I got the same issue. The cookie was not set by the browser,
I tryed a lot of possible solutions but what solve my problem was change
the domain name. I deployed my API as server.mydomain.com and my frontend
was anotherdomain.app and CORS was properly configured. I was able to
send request to 'open' routes, but when I tried to login the cookie was
ignored by the browser. So, when I changed the frontend to mydomain.com
the cookie was set perfectly.
Help Plz,
Can you tell me what changes you do in domain because I am using vercel
and my client domain is => https://video-streamer-app-frontend.vercel.app
and my server domain is => https://video-streamer-app.vercel.app
in localhost its storing cookies in browser but in deployment it do not
I am also using cors with withcredentials and origin at server side
app.use(
cors({
origin: "https://video-streamer-app-frontend.vercel.app",
credentials: true,
})
);
and also using
axios.defaults.withCredentials = true;
at client side
plz help!!!
—
Reply to this email directly, view it on GitHub
<#4907 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ANTW7FBVS6X63TMIRNA6U4DXRAQRXANCNFSM557ULXAQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
It did'nt do anything bro. |
I am also having same issue. Cookie works in development but not in production. My frontend is deployed on like domain.com and backend on cloud.cyclic.app |
@Gaurav200247 did you try setting same-site: "none" in cookie? res.cookie("refreshtoken", refreshToken, {
httpOnly: true,
sameSite: "none",
secure: true,
// maxAge: 24 * 60 * 60 * 1000, // 1 day
maxAge: 3 * 60 * 1000,
path: "/api/auth/refresh",
}); i just implemented a full stack auth in which server and client are on different domains so setting sameSite: "strict" will stop cookie at client side because of different domain. and cors settings are like this app.use(
cors({
origin: ["http://localhost:5173", process.env.CLIENT_BASE_URL as string],
methods: ["GET", "POST", "PUT", "DELETE"],
credentials: true,
})
); |
I have tried what you are saying my cookie config are : and using cors as : in production app works fine cookie is saving but in deployment no cookie is saved I tried logging response headers and got this : Response Headers: {cache-control: 'public, max-age=0, must-revalidate', content-type: 'application/json; charset=utf-8'} i am getting max Age = 0; can someone help. |
using sameSite:"none" fixed my issue, Thanks. |
Hello, I am facing the same issue, I've tryed everything. My server is at localhost. Server
Just in case, I set the
Then I set the cookie when a new user is created:
Client The axios instance, set credentials to True.
However, set cookies is empty in the devTools, and in the server side, Node : 18.18.0 |
my is not working |
Thank you so much bro...I've spent 3 days because of this issue. |
For anyone that's facing this problem, what worked for me was disabling the adblocker on my deployed website. Here's the code I used for setting the cookies
|
what was the issue can you please help me out with the code sample |
👋 Hey everyone,
|
Summary
I'm new user from nodejs (expressjs) and axios too and I have a problem. I set cookie from nodejs server with:
I can see response cookie from browser but in storage I can not see. I use res.header do the same, nothing happen. httpOnly: false does not work.
And in client I try:
I can not find other ways to do this, every result I got in google do this but I dont know why that not working for me. With Postman it automatic send cookie every request. Please help me!
Environment
The text was updated successfully, but these errors were encountered: