Skip to content

Commit

Permalink
fix: add error checking when creating verification code (#3328)
Browse files Browse the repository at this point in the history
  • Loading branch information
hperl committed Jun 19, 2023
1 parent 9d3ef0d commit 7182eca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
15 changes: 9 additions & 6 deletions persistence/sql/persister_verification.go
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 {
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
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

0 comments on commit 7182eca

Please sign in to comment.