Skip to content

Conversation

@jfyne
Copy link
Contributor

@jfyne jfyne commented Aug 24, 2023

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 vet errors.

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.
Copy link
Owner

@johnsto johnsto left a 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.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link
Owner

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
Copy link
Owner

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()
Copy link
Owner

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.

Suggested change
ctx := context.TODO()
ctx := context.Background()

}

func TestVerifyTokenWithOptions(t *testing.T) {
ctx := context.TODO()
Copy link
Owner

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.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Owner

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?

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.

2 participants