This repository was archived by the owner on Jul 4, 2025. It is now read-only.
WIP: Generate tokens with variable expiry date#25
Open
rhwilr wants to merge 3 commits intoadonisjs:developfrom
Open
WIP: Generate tokens with variable expiry date#25rhwilr wants to merge 3 commits intoadonisjs:developfrom
rhwilr wants to merge 3 commits intoadonisjs:developfrom
Conversation
RomainLanz
approved these changes
Dec 17, 2018
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi @thetutlage
I added the
expires_atfield to tokens as we discussed in #24. So far it works, but I have two questions I'd like to get your input on:1:
In order to allow you to set a different duration for each token, I had two options: Add a parameter to all methods (
generateToken,register,updateEmail,updateProfile) that generate a token, or add a chainable method. I went with the latter since it would have made it a bit awkward to pass the parameter down. And I especially didn't like the signature forregister:So currently I use the
isValidFormethod to set the parameter and returnthisto allow chaining. But this means I have to reset the value after generating a token.I'm not happy with either of those options. So I want to ask you what you prefer or if you have a better idea?
2:
What should happen with existing tokens when users upgrade?
Currently, I treat tokens without an expiry date as invalid. To make the migration easy we could add a fallback: If
expires_atis null, we fall back to the previous behavior and check theupdated_atfield. However, this fallback would only ever be used for 24 hours after the upgrade.I would prefer the fallback option. So I tried to construct a query, but it turns out to be quite difficult since the
queryparameter is sometimes auser.tokens()relationship which would lead to a wrongorclause.This was my attempt:
Looking forward to your feedback.