Skip to content

feat: Allow post verify actions.#5

Open
jfyne wants to merge 1 commit into
johnsto:masterfrom
human-made-machine:jf/allow-more-actions-on-verify
Open

feat: Allow post verify actions.#5
jfyne wants to merge 1 commit into
johnsto:masterfrom
human-made-machine:jf/allow-more-actions-on-verify

Conversation

@jfyne

@jfyne jfyne commented Aug 24, 2023

Copy link
Copy Markdown
Contributor

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.

@johnsto johnsto left a comment

Copy link
Copy Markdown
Owner

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 :)

Comment thread passwordless.go
// 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
Copy Markdown
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 thread passwordless.go
Comment on lines +122 to +125
if valid {
return valid, s.Delete(ctx, uid)
}
return valid, nil

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

Comment thread passwordless.go
return VerifyToken(ctx, p.Store, uid, token)
}

func (p *Passwordless) VerifyTokenWithOptions(ctx context.Context, uid, token string, actions ...PostVerifyAction) (bool, error) {

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

Comment thread passwordless.go
return VerifyTokenWithOptions(ctx, s, uid, token, WithValidDelete())
}

// VerifyTokenWithOptions

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

Comment thread passwordless_test.go
}

func TestPasswordless(t *testing.T) {
ctx := context.TODO()

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

Comment thread passwordless_test.go
}

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

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

Comment thread passwordless.go
}
}

// PostVerifyAction is an action to take after validation has succesfully occured.

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

Comment thread passwordless.go
}

// 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
Copy Markdown
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