Skip to content
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

Allow maxAge 0 and make defaultMaxAge a variable to create a non-persistent cookie #58

Closed
wants to merge 2 commits into from
Closed

Allow maxAge 0 and make defaultMaxAge a variable to create a non-persistent cookie #58

wants to merge 2 commits into from

Conversation

t-tiger
Copy link

@t-tiger t-tiger commented Jan 16, 2019

Related to the following PR.
#55

Here is the outline of changes.

  • Allow maxAge 0 when saving a redis store.
  • Make defaultMaxAge a variable and allow to change this value from outside.

Why allow MaxAge to be 0?

When setting cookie, by not setting a MaxAge, we can make a one-time cookie and user loses authentication state after closing the browser. And then, user will open website again, the login state would not be persisted and we can prompt to login again.

But if redis TTL is set to zero, server loses the authentication information while user is staying in the browser, and the user's login status will be disappeared

I think it's not uncommon to use redis with some TTL and to set the session's MaxAge to 0, which is required for my product indeed.

There is already a defaultMaxAge property, but now maxAge is not allowed to be 0, so defaultMaxAge has no chance to be used.

But this approach is flexible, allowing maxAge to be 0, we can set different expiration for session and redis.

Once I'd like to give arguments to Save function, but this is an implementation of Interface, so we can't change function structure.

So I accomplish this by changing defaultMaxAge from outside. With this approach we can realize this use case without breaking the implementation of interface.

@t-tiger t-tiger changed the title Allow maxAge 0 and make defaultMaxAge a variable to create a one-time cookie Allow maxAge 0 and make defaultMaxAge a variable to create a non-persistent cookie Jan 17, 2019
@t-tiger t-tiger closed this Jan 31, 2019
@t-tiger t-tiger reopened this Jan 31, 2019
@t-tiger
Copy link
Author

t-tiger commented Jan 31, 2019

@AnikHasibul Thanks for approve. But merging is blocked by Travic CI checking.

Failed in command of go get. This problem seems to be common case for 1.6 or eariler version and I think it's not related with this PR. I actually need these changes, so what should I do?

@t-tiger t-tiger closed this Jan 8, 2020
@wwn0594
Copy link

wwn0594 commented Mar 15, 2021

Any updates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants