Closed Hitan999 closed 5 months ago
Hey there,
It's not entirely clear to me what you were hoping to achieve from what you had written. Deletion of the cookie is up to the browser: https://datatracker.ietf.org/doc/html/rfc6265#section-5.2.2
And in the sessions code the way we implement this is if the max age is 0 or less than we set it to an already-passed time so that the cookie will be considered expired by the browser: https://github.com/gorilla/sessions/blob/bdabf0ac29ab2354c0674cb0dcd3a4f31f53589d/sessions.go#L185
So it seems proper to me that the session instance stays around until the next request.
So far as I can tell, this is expected behaviour. I'm going to close this out but if you need further clarification or can provide more details about what exactly you're expecting to happen that isn't happening I'm happy to try to help further!
Is there an existing issue for this?
Current Behavior
I wrote Gorilla Sessions to manage login and logout sessions a platform, and I attach below the code for the logout, which is based on setting MaxAge = -1 in the current session. However, it looks like setting MaxAge to -1 does not delete the session, and I am confused about what is happening.
Store is initialized:
For logging out, the function first reads the existing session:
then prints the session details, changes MaxAge to -1, and saves the new session:
I then re-read the session and check if the options have been saved correctly, and they do. But it looks that the session is not really deleted straight away, or it would not be able to read the session after the save. Moreover, when the first part of the code reads the session, it gives "false" to Secure and HttpOnly, although during login process the session was created with the same Options (e.g. "true").
If I now remove the other options (Secure, etc.) the cookie will not match with the cookie in the browser, thus will not be set to expired, and refreshing the sessions will still look active. The check of the session will also show that MaxAge is back to 3600.
Could someone say what is happening, and probably where I am making mistakes?
Expected Behavior
No response
Steps To Reproduce
No response
Anything else?
No response