Skip to content

Commit

Permalink
fix: update migration
Browse files Browse the repository at this point in the history
  • Loading branch information
J0 committed Sep 30, 2024
1 parent e43a178 commit 021b320
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
14 changes: 13 additions & 1 deletion internal/models/factor.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ type Factor struct {
Phone storage.NullString `json:"phone" db:"phone"`
LastChallengedAt *time.Time `json:"last_challenged_at" db:"last_challenged_at"`
WebAuthnCredential *WebAuthnCredential `json:"-" db:"web_authn_credential"`
AAGUID *uuid.UUID `json:"aaguid" db:"aaguid"`
}

type WebAuthnCredential struct {
Expand Down Expand Up @@ -223,7 +224,18 @@ func (f *Factor) SaveWebAuthnCredential(tx *storage.Connection, credential *weba
f.WebAuthnCredential = &WebAuthnCredential{
Credential: *credential,
}
return tx.UpdateOnly(f, "web_authn_credential", "updated_at")

if len(credential.Authenticator.AAGUID) > 0 {
aaguidUUID, err := uuid.FromBytes(credential.Authenticator.AAGUID)
if err != nil {
return fmt.Errorf("failed to convert AAGUID to UUID: %w", err)
}
f.AAGUID = &aaguidUUID
} else {
f.AAGUID = nil
}

return tx.UpdateOnly(f, "web_authn_credential", "aaguid", "updated_at")
}

func FindFactorByFactorID(conn *storage.Connection, factorID uuid.UUID) (*Factor, error) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
alter table {{ index .Options "Namespace" }}.mfa_factors add column if not exists web_authn_credential jsonb null;
alter table {{ index .Options "Namespace" }}.mfa_factors add column if not exists aaguid uuid null;
alter table {{ index .Options "Namespace" }}.mfa_challenges add column if not exists web_authn_session_data jsonb null;

0 comments on commit 021b320

Please sign in to comment.