-
Notifications
You must be signed in to change notification settings - Fork 9
feat: Allow post verify actions. #5
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
base: master
Are you sure you want to change the base?
feat: Allow post verify actions. #5
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
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // WithValidDelete when a token is a valid, this deletes it from the store. | |
| // WithValidDelete deletes a token from the store when validation succeeds. |
| if valid { | ||
| return valid, s.Delete(ctx, uid) | ||
| } | ||
| return valid, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing method doc comment.
| return VerifyTokenWithOptions(ctx, s, uid, token, WithValidDelete()) | ||
| } | ||
|
|
||
| // VerifyTokenWithOptions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests should use the background context.
| ctx := context.TODO() | |
| ctx := context.Background() |
| } | ||
|
|
||
| func TestVerifyTokenWithOptions(t *testing.T) { | ||
| ctx := context.TODO() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests should use the background context.
| } | ||
| } | ||
|
|
||
| // PostVerifyAction is an action to take after validation has succesfully occured. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unclear on the purpose of the bool in the return values here. When would it ever be different to the incoming valid value?
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.