[enter image description here][1]Im developed web app react frontend and node backend.when user login I try to save cookie in browser .in postman testing cookie show but not save in browser.(I used also jwt authentication)In browser this error show,* Indicate whether a cookie is intended to be set in a cross-site context by specifying its SameSite attribute* .and I update with sameSite none and secure true but still not save cookie in browser.How to slove this
Asked
Active
Viewed 221 times
2 Answers
0
Did you enable the Cors middleware on the server-side? Here's how you can do it How to enable cors nodejs with express?

nicklee
- 55
- 1
- 7
-
I did app.use(cors({ origin: "http://127.0.0.1:5173", credentials: true })); also add userCredential true in frontend and .cookie("accessToken", token, { httpOnly: true, sameSite: "none", secure: true, }) do these changes but still can not save cookie in browser – Tharindu Madhushan Apr 28 '23 at 06:05
-
Try removing all the options. Leave just plain `app.use(cors())`. – nicklee Apr 28 '23 at 06:06
-
It s getting cors errors – Tharindu Madhushan Apr 28 '23 at 06:12
-
sloved .cors origin should changed as localhost:5173 – Tharindu Madhushan Apr 28 '23 at 17:56
0
If you are hosting your web app on localhost you should set secure:false
or else cookies are not going to work. You should set secure:true
only when you deploy your web app. The reason is setting this option to true says that the cookies should be send over https (secure) connection but when you are on localhost you are on http (not secure) connection so coookies will not be sent. For more info check a previous question:
Why setting the cookie.secure to True in express session allows session id and data to persist?

PTsag
- 108
- 2
- 9
-
I do but not save cookie below is the error message .It says my accessToken Affected Resolve this issue by updating the attributes of the cookie: Specify SameSite=None and Secure if the cookie is intended to be set in cross-site contexts. Note that only cookies sent over HTTPS may use the Secure attribute. Specify SameSite=Strict or SameSite=Lax if the cookie should not be set by cross-site requests. 1 cookie Name Domain & Path accessToken localhost/ – Tharindu Madhushan Apr 28 '23 at 10:57
-