feat: Allow post verify actions.#5
Open
jfyne wants to merge 1 commit into
Open
Conversation
This change allows post verify actions to occur. For example you can now choose if a delete of a token should happen after its been validated.
johnsto
requested changes
Oct 14, 2023
johnsto
left a comment
Owner
There was a problem hiding this comment.
Cheers for this PR! A few comments :)
| // PostVerifyAction is an action to take after validation has succesfully occured. | ||
| type PostVerifyAction func(ctx context.Context, s TokenStore, uid, token string, valid bool) (bool, error) | ||
|
|
||
| // WithValidDelete when a token is a valid, this deletes it from the store. |
Owner
There was a problem hiding this comment.
Suggested change
| // WithValidDelete when a token is a valid, this deletes it from the store. | |
| // WithValidDelete deletes a token from the store when validation succeeds. |
Comment on lines
+122
to
+125
| if valid { | ||
| return valid, s.Delete(ctx, uid) | ||
| } | ||
| return valid, nil |
Owner
There was a problem hiding this comment.
Suggested change
| if valid { | |
| return valid, s.Delete(ctx, uid) | |
| } | |
| return valid, nil | |
| if valid { | |
| return true, s.Delete(ctx, uid) | |
| } | |
| return false, nil |
| return VerifyToken(ctx, p.Store, uid, token) | ||
| } | ||
|
|
||
| func (p *Passwordless) VerifyTokenWithOptions(ctx context.Context, uid, token string, actions ...PostVerifyAction) (bool, error) { |
| return VerifyTokenWithOptions(ctx, s, uid, token, WithValidDelete()) | ||
| } | ||
|
|
||
| // VerifyTokenWithOptions |
Owner
There was a problem hiding this comment.
Incomplete func doc comment here. It would be good to clearly describe how actions work, and what happens if an action returns an error, for example.
| } | ||
|
|
||
| func TestPasswordless(t *testing.T) { | ||
| ctx := context.TODO() |
Owner
There was a problem hiding this comment.
Tests should use the background context.
Suggested change
| ctx := context.TODO() | |
| ctx := context.Background() |
| } | ||
|
|
||
| func TestVerifyTokenWithOptions(t *testing.T) { | ||
| ctx := context.TODO() |
Owner
There was a problem hiding this comment.
Tests should use the background context.
| } | ||
| } | ||
|
|
||
| // PostVerifyAction is an action to take after validation has succesfully occured. |
Owner
There was a problem hiding this comment.
Suggested change
| // PostVerifyAction is an action to take after validation has succesfully occured. | |
| // PostVerifyAction is an action to take if validation succeeds. |
| } | ||
|
|
||
| // PostVerifyAction is an action to take after validation has succesfully occured. | ||
| type PostVerifyAction func(ctx context.Context, s TokenStore, uid, token string, valid bool) (bool, error) |
Owner
There was a problem hiding this comment.
Unclear on the purpose of the bool in the return values here. When would it ever be different to the incoming valid value?
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This change allows post verify actions to occur. For example you can now choose if a delete of a token should happen after its been validated.
I have also tidied up some
go veterrors.