skip to Main Content

I am setting cookie on signup route
but when i go to home route, then cookie disappears from browser
The cookie is only present on signup route, when i change route then it gets deleted
Any solution for this?

res.cookie('token', token, { maxAge: 3600*1000, httpOnly: true, })

2

Answers


  1. Must specify the path for your entire site instead of signup route. Give a look into path and SameSite attributes.

    Login or Signup to reply.
  2. It sounds like the issue might be related to the cookie’s configuration, particularly the path or domain options.

    By default, a cookie is only available to the path where it’s set. To make it accessible across all routes, set the path option to ‘/’.

    Ensure that the cookie’s domain is set correctly, especially if you’re working with subdomains.

    res.cookie('token', token, { 
        maxAge: 3600 * 1000, 
        httpOnly: true, 
        path: '/'  // Make the cookie available across all routes
    });
    

    This should make the cookie available on all routes of your application. If the issue persists, ensure that:

    • The browser is not blocking cookies.
    • You are not accidentally clearing or overwriting the cookie elsewhere in your code.
    • The domain and path settings are correct, especially if your application spans multiple subdomains.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search