MCPcopy Create free account
hub / github.com/supabase/auth / adminUserUpdateFactor

Method adminUserUpdateFactor

internal/api/admin.go:610–654  ·  view source on GitHub ↗

adminUserUpdate updates a single factor object

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

608
609// adminUserUpdate updates a single factor object
610func (a *API) adminUserUpdateFactor(w http.ResponseWriter, r *http.Request) error {
611 ctx := r.Context()
612 config := a.config
613 factor := getFactor(ctx)
614 user := getUser(ctx)
615 adminUser := getAdminUser(ctx)
616 params := &adminUserUpdateFactorParams{}
617 db := a.db.WithContext(ctx)
618
619 if err := retrieveRequestParams(r, params); err != nil {
620 return err
621 }
622
623 err := db.Transaction(func(tx *storage.Connection) error {
624 if params.FriendlyName != "" {
625 if terr := factor.UpdateFriendlyName(tx, params.FriendlyName); terr != nil {
626 return terr
627 }
628 }
629
630 if params.Phone != "" && factor.IsPhoneFactor() {
631 phone, err := validatePhone(params.Phone)
632 if err != nil {
633 return apierrors.NewBadRequestError(apierrors.ErrorCodeValidationFailed, "Invalid phone number format (E.164 required)")
634 }
635 if terr := factor.UpdatePhone(tx, phone); terr != nil {
636 return terr
637 }
638 }
639
640 if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, adminUser, models.UpdateFactorAction, "", map[string]interface{}{
641 "user_id": user.ID,
642 "factor_id": factor.ID,
643 "factor_type": factor.FactorType,
644 }); terr != nil {
645 return terr
646 }
647 return nil
648 })
649 if err != nil {
650 return err
651 }
652
653 return sendJSON(w, http.StatusOK, factor)
654}

Callers

nothing calls this directly

Calls 13

NewBadRequestErrorFunction · 0.92
NewAuditLogEntryFunction · 0.92
getFactorFunction · 0.85
getUserFunction · 0.85
getAdminUserFunction · 0.85
retrieveRequestParamsFunction · 0.85
validatePhoneFunction · 0.85
sendJSONFunction · 0.85
WithContextMethod · 0.80
TransactionMethod · 0.80
IsPhoneFactorMethod · 0.80
UpdatePhoneMethod · 0.80

Tested by

no test coverage detected