Skip to content

Commit afd4467

Browse files
committed
fix: update phone admin methods
1 parent 7e472ad commit afd4467

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

internal/api/admin.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -618,11 +618,9 @@ func (a *API) adminUserUpdateFactor(w http.ResponseWriter, r *http.Request) erro
618618
return terr
619619
}
620620
}
621-
if params.FactorType != "" {
622-
if params.FactorType != models.TOTP {
623-
return badRequestError(ErrorCodeValidationFailed, "Factor Type not valid")
624-
}
625-
if terr := factor.UpdateFactorType(tx, params.FactorType); terr != nil {
621+
622+
if params.Phone != "" && factor.IsPhoneFactor() {
623+
if terr := factor.UpdatePhone(tx, params.Phone); terr != nil {
626624
return terr
627625
}
628626
}

internal/models/factor.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func (factorState FactorState) String() string {
3232

3333
const TOTP = "totp"
3434
const Phone = "phone"
35+
const WebAuthn = "webauthn"
3536

3637
type AuthenticationMethod int
3738

@@ -245,18 +246,17 @@ func (f *Factor) UpdateFriendlyName(tx *storage.Connection, friendlyName string)
245246
return tx.UpdateOnly(f, "friendly_name", "updated_at")
246247
}
247248

249+
func (f *Factor) UpdatePhone(tx *storage.Connection, phone string) error {
250+
f.Phone = phone
251+
return tx.UpdateOnly(f, "phone", "updated_at")
252+
}
253+
248254
// UpdateStatus modifies the factor status
249255
func (f *Factor) UpdateStatus(tx *storage.Connection, state FactorState) error {
250256
f.Status = state.String()
251257
return tx.UpdateOnly(f, "status", "updated_at")
252258
}
253259

254-
// UpdateFactorType modifies the factor type
255-
func (f *Factor) UpdateFactorType(tx *storage.Connection, factorType string) error {
256-
f.FactorType = factorType
257-
return tx.UpdateOnly(f, "factor_type", "updated_at")
258-
}
259-
260260
func (f *Factor) DowngradeSessionsToAAL1(tx *storage.Connection) error {
261261
sessions, err := FindSessionsByFactorID(tx, f.ID)
262262
if err != nil {

0 commit comments

Comments
 (0)