WIP: Generate tokens with variable expiry date #25
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_at
field 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
isValidFor
method to set the parameter and returnthis
to 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_at
is null, we fall back to the previous behavior and check theupdated_at
field. 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
query
parameter is sometimes auser.tokens()
relationship which would lead to a wrongor
clause.This was my attempt:
Looking forward to your feedback.