MCPcopy Index your code
hub / github.com/supabase/auth / adminUserUpdate

Method adminUserUpdate

internal/api/admin.go:142–322  ·  view source on GitHub ↗

adminUserUpdate updates a single user object

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

Source from the content-addressed store, hash-verified

140
141// adminUserUpdate updates a single user object
142func (a *API) adminUserUpdate(w http.ResponseWriter, r *http.Request) error {
143 ctx := r.Context()
144 db := a.db.WithContext(ctx)
145 config := a.config
146 user := getUser(ctx)
147 adminUser := getAdminUser(ctx)
148 params, err := a.getAdminParams(r)
149 if err != nil {
150 return err
151 }
152
153 if params.Email != "" {
154 params.Email, err = a.validateEmail(params.Email)
155 if err != nil {
156 return err
157 }
158 }
159
160 if params.Phone != "" {
161 params.Phone, err = validatePhone(params.Phone)
162 if err != nil {
163 return err
164 }
165 }
166
167 var banDuration *time.Duration
168 if params.BanDuration != "" {
169 duration := time.Duration(0)
170 if params.BanDuration != "none" {
171 duration, err = time.ParseDuration(params.BanDuration)
172 if err != nil {
173 return apierrors.NewBadRequestError(apierrors.ErrorCodeValidationFailed, "invalid format for ban duration: %v", err)
174 }
175 }
176 banDuration = &duration
177 }
178
179 if params.Password != nil {
180 password := *params.Password
181
182 if err := a.checkPasswordStrength(ctx, password); err != nil {
183 return err
184 }
185
186 if err := user.SetPassword(ctx, password, config.Security.DBEncryption.Encrypt, config.Security.DBEncryption.EncryptionKeyID, config.Security.DBEncryption.EncryptionKey); err != nil {
187 return err
188 }
189 }
190
191 err = db.Transaction(func(tx *storage.Connection) error {
192 if params.Role != "" {
193 if terr := user.SetRole(tx, params.Role); terr != nil {
194 return terr
195 }
196 }
197
198 if params.EmailConfirm {
199 if terr := user.Confirm(tx); terr != nil {

Callers

nothing calls this directly

Calls 15

getAdminParamsMethod · 0.95
validateEmailMethod · 0.95
checkPasswordStrengthMethod · 0.95
createNewIdentityMethod · 0.95
NewBadRequestErrorFunction · 0.92
IsNotFoundErrorFunction · 0.92
NewAuditLogEntryFunction · 0.92
NewInternalServerErrorFunction · 0.92
getUserFunction · 0.85
getAdminUserFunction · 0.85
validatePhoneFunction · 0.85

Tested by

no test coverage detected