Skip to content
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

fix: add error checking when creating verification code #3328

Merged
merged 1 commit into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 9 additions & 6 deletions persistence/sql/persister_verification.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/pkg/errors"

"github.com/ory/herodot"
"github.com/ory/kratos/identity"
"github.com/ory/kratos/persistence/sql/update"

Expand Down Expand Up @@ -257,12 +258,14 @@ func (p *Persister) CreateVerificationCode(ctx context.Context, c *code.CreateVe
NID: p.NetworkID(ctx),
}

if c.VerifiableAddress != nil {
verificationCode.VerifiableAddress = c.VerifiableAddress
verificationCode.VerifiableAddressID = uuid.NullUUID{
UUID: c.VerifiableAddress.ID,
Valid: true,
}
if c.VerifiableAddress == nil {
aeneasr marked this conversation as resolved.
Show resolved Hide resolved
return nil, errors.WithStack(herodot.ErrNotFound.WithReason("can't create a verification code without a verifiable address"))
}

verificationCode.VerifiableAddress = c.VerifiableAddress
verificationCode.VerifiableAddressID = uuid.NullUUID{
UUID: c.VerifiableAddress.ID,
Valid: true,
}

// This should not create the request eagerly because otherwise we might accidentally create an address that isn't
Expand Down
4 changes: 2 additions & 2 deletions selfservice/strategy/code/verification_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type VerificationCode struct {

// VerifiableAddress links this code to a verification address.
// required: true
VerifiableAddress *identity.VerifiableAddress `json:"verification_address" belongs_to:"identity_verifiable_addresses" fk_id:"VerificationAddVerifiableAddressIDressID"`
VerifiableAddress *identity.VerifiableAddress `json:"verification_address" belongs_to:"identity_verifiable_addresses"`

// ExpiresAt is the time (UTC) when the code expires.
// required: true
Expand All @@ -52,7 +52,7 @@ type VerificationCode struct {
NID uuid.UUID `json:"-" faker:"-" db:"nid"`
}

func (VerificationCode) TableName(ctx context.Context) string {
func (VerificationCode) TableName(context.Context) string {
return "identity_verification_codes"
}

Expand Down