cookies-next icon indicating copy to clipboard operation
cookies-next copied to clipboard

Cookies are clear automatically when close the window

Open mohitTecorb opened this issue 2 years ago • 12 comments

mohitTecorb avatar Jan 13 '23 10:01 mohitTecorb

Same issue here

Ankan002 avatar Feb 22 '23 18:02 Ankan002

Check your browser settings if it is clearing all the cookies when you close the window.

Velik0ff avatar Mar 06 '23 11:03 Velik0ff

you have to set a max age or it will clear automatically

Jared-Dahlke avatar Mar 18 '23 23:03 Jared-Dahlke

Having the same issue as well, despite setting both maxAge and expires. I wonder if that's because I am setting the cookie on the client side.

tnsengimana avatar Mar 20 '23 21:03 tnsengimana

My issue resolved , after debug my whole application , I was using SSR in my application and when ever i open the page , my get_User_Details API hit without token , that why getting session expire . and clear all the cookies .

you have to check you Application why your cookies clear .

mohitTecorb avatar Mar 27 '23 06:03 mohitTecorb

I am also facing the same problem despite setting maxAge and expires. Is setCookies deprecated?

anushkagarg5653 avatar Apr 03 '23 08:04 anushkagarg5653

I thought I was the only one. I have spent hours trying to fix but the issue still persists.

orsdev avatar Aug 18 '23 05:08 orsdev

I'm unsure if this is the solution, but when I store the cookie name in an environment file and use it, the cookie seems to disappear after a page refresh. However, when I hardcode the name instead of loading it from the environment, the issue gets resolved for me.

orsdev avatar Aug 18 '23 06:08 orsdev

Actually for me the issue was solved as I later found out that I was using a third party cookie and not a first party one.

Ankan002 avatar Aug 18 '23 07:08 Ankan002

I'm unsure if this is the solution, but when I store the cookie name in an environment file and use it, the cookie seems to disappear after a page refresh. However, when I hardcode the name instead of loading it from the environment, the issue gets resolved for me.

I guess the env is not getting loaded correctly also this was also an issue with me in the combined approach in App directory and pages directory.

Ankan002 avatar Aug 18 '23 08:08 Ankan002

I'm unsure if this is the solution, but when I store the cookie name in an environment file and use it, the cookie seems to disappear after a page refresh. However, when I hardcode the name instead of loading it from the environment, the issue gets resolved for me.

This also the fix (not sure if this is correct) for me, but I found another case if you hardcode the cookie key, let's say in a constants.ts, and import the cookie key the expire/max-age is set to session thus clearing the cookie when the browser is closed.

RafaelJon avatar Aug 18 '23 19:08 RafaelJon

I'm unsure if this is the solution, but when I store the cookie name in an environment file and use it, the cookie seems to disappear after a page refresh. However, when I hardcode the name instead of loading it from the environment, the issue gets resolved for me.

This also the fix (not sure if this is correct) for me, but I found another case if you hardcode the cookie key, let's say in a constants.ts, and import the cookie key the expire/max-age is set to session thus clearing the cookie when the browser is closed.

This is also happening with other cookie library, maybe it is because "use client" when setting the cookie but still I don't find the cause

RafaelJon avatar Aug 18 '23 19:08 RafaelJon