@@ -10,6 +10,7 @@ import (
10
10
"github.com/gofrs/uuid"
11
11
"github.com/pkg/errors"
12
12
"github.com/sethvargo/go-password/password"
13
+ "github.com/supabase/auth/internal/api/apierrors"
13
14
"github.com/supabase/auth/internal/api/provider"
14
15
"github.com/supabase/auth/internal/models"
15
16
"github.com/supabase/auth/internal/observability"
@@ -53,15 +54,15 @@ func (a *API) loadUser(w http.ResponseWriter, r *http.Request) (context.Context,
53
54
54
55
userID , err := uuid .FromString (chi .URLParam (r , "user_id" ))
55
56
if err != nil {
56
- return nil , notFoundError (ErrorCodeValidationFailed , "user_id must be an UUID" )
57
+ return nil , notFoundError (apierrors . ErrorCodeValidationFailed , "user_id must be an UUID" )
57
58
}
58
59
59
60
observability .LogEntrySetField (r , "user_id" , userID )
60
61
61
62
u , err := models .FindUserByID (db , userID )
62
63
if err != nil {
63
64
if models .IsNotFoundError (err ) {
64
- return nil , notFoundError (ErrorCodeUserNotFound , "User not found" )
65
+ return nil , notFoundError (apierrors . ErrorCodeUserNotFound , "User not found" )
65
66
}
66
67
return nil , internalServerError ("Database error loading user" ).WithInternalError (err )
67
68
}
@@ -76,15 +77,15 @@ func (a *API) loadFactor(w http.ResponseWriter, r *http.Request) (context.Contex
76
77
user := getUser (ctx )
77
78
factorID , err := uuid .FromString (chi .URLParam (r , "factor_id" ))
78
79
if err != nil {
79
- return nil , notFoundError (ErrorCodeValidationFailed , "factor_id must be an UUID" )
80
+ return nil , notFoundError (apierrors . ErrorCodeValidationFailed , "factor_id must be an UUID" )
80
81
}
81
82
82
83
observability .LogEntrySetField (r , "factor_id" , factorID )
83
84
84
85
factor , err := user .FindOwnedFactorByID (db , factorID )
85
86
if err != nil {
86
87
if models .IsNotFoundError (err ) {
87
- return nil , notFoundError (ErrorCodeMFAFactorNotFound , "Factor not found" )
88
+ return nil , notFoundError (apierrors . ErrorCodeMFAFactorNotFound , "Factor not found" )
88
89
}
89
90
return nil , internalServerError ("Database error loading factor" ).WithInternalError (err )
90
91
}
@@ -108,12 +109,12 @@ func (a *API) adminUsers(w http.ResponseWriter, r *http.Request) error {
108
109
109
110
pageParams , err := paginate (r )
110
111
if err != nil {
111
- return badRequestError (ErrorCodeValidationFailed , "Bad Pagination Parameters: %v" , err ).WithInternalError (err )
112
+ return badRequestError (apierrors . ErrorCodeValidationFailed , "Bad Pagination Parameters: %v" , err ).WithInternalError (err )
112
113
}
113
114
114
115
sortParams , err := sort (r , map [string ]bool {models .CreatedAt : true }, []models.SortField {{Name : models .CreatedAt , Dir : models .Descending }})
115
116
if err != nil {
116
- return badRequestError (ErrorCodeValidationFailed , "Bad Sort Parameters: %v" , err )
117
+ return badRequestError (apierrors . ErrorCodeValidationFailed , "Bad Sort Parameters: %v" , err )
117
118
}
118
119
119
120
filter := r .URL .Query ().Get ("filter" )
@@ -169,7 +170,7 @@ func (a *API) adminUserUpdate(w http.ResponseWriter, r *http.Request) error {
169
170
if params .BanDuration != "none" {
170
171
duration , err = time .ParseDuration (params .BanDuration )
171
172
if err != nil {
172
- return badRequestError (ErrorCodeValidationFailed , "invalid format for ban duration: %v" , err )
173
+ return badRequestError (apierrors . ErrorCodeValidationFailed , "invalid format for ban duration: %v" , err )
173
174
}
174
175
}
175
176
banDuration = & duration
@@ -338,7 +339,7 @@ func (a *API) adminUserCreate(w http.ResponseWriter, r *http.Request) error {
338
339
}
339
340
340
341
if params .Email == "" && params .Phone == "" {
341
- return badRequestError (ErrorCodeValidationFailed , "Cannot create a user without either an email or phone" )
342
+ return badRequestError (apierrors . ErrorCodeValidationFailed , "Cannot create a user without either an email or phone" )
342
343
}
343
344
344
345
var providers []string
@@ -350,7 +351,7 @@ func (a *API) adminUserCreate(w http.ResponseWriter, r *http.Request) error {
350
351
if user , err := models .IsDuplicatedEmail (db , params .Email , aud , nil ); err != nil {
351
352
return internalServerError ("Database error checking email" ).WithInternalError (err )
352
353
} else if user != nil {
353
- return unprocessableEntityError (ErrorCodeEmailExists , DuplicateEmailMsg )
354
+ return unprocessableEntityError (apierrors . ErrorCodeEmailExists , DuplicateEmailMsg )
354
355
}
355
356
providers = append (providers , "email" )
356
357
}
@@ -363,13 +364,13 @@ func (a *API) adminUserCreate(w http.ResponseWriter, r *http.Request) error {
363
364
if exists , err := models .IsDuplicatedPhone (db , params .Phone , aud ); err != nil {
364
365
return internalServerError ("Database error checking phone" ).WithInternalError (err )
365
366
} else if exists {
366
- return unprocessableEntityError (ErrorCodePhoneExists , "Phone number already registered by another user" )
367
+ return unprocessableEntityError (apierrors . ErrorCodePhoneExists , "Phone number already registered by another user" )
367
368
}
368
369
providers = append (providers , "phone" )
369
370
}
370
371
371
372
if params .Password != nil && params .PasswordHash != "" {
372
- return badRequestError (ErrorCodeValidationFailed , "Only a password or a password hash should be provided" )
373
+ return badRequestError (apierrors . ErrorCodeValidationFailed , "Only a password or a password hash should be provided" )
373
374
}
374
375
375
376
if (params .Password == nil || * params .Password == "" ) && params .PasswordHash == "" {
@@ -389,18 +390,18 @@ func (a *API) adminUserCreate(w http.ResponseWriter, r *http.Request) error {
389
390
390
391
if err != nil {
391
392
if errors .Is (err , bcrypt .ErrPasswordTooLong ) {
392
- return badRequestError (ErrorCodeValidationFailed , err .Error ())
393
+ return badRequestError (apierrors . ErrorCodeValidationFailed , err .Error ())
393
394
}
394
395
return internalServerError ("Error creating user" ).WithInternalError (err )
395
396
}
396
397
397
398
if params .Id != "" {
398
399
customId , err := uuid .FromString (params .Id )
399
400
if err != nil {
400
- return badRequestError (ErrorCodeValidationFailed , "ID must conform to the uuid v4 format" )
401
+ return badRequestError (apierrors . ErrorCodeValidationFailed , "ID must conform to the uuid v4 format" )
401
402
}
402
403
if customId == uuid .Nil {
403
- return badRequestError (ErrorCodeValidationFailed , "ID cannot be a nil uuid" )
404
+ return badRequestError (apierrors . ErrorCodeValidationFailed , "ID cannot be a nil uuid" )
404
405
}
405
406
user .ID = customId
406
407
}
@@ -418,7 +419,7 @@ func (a *API) adminUserCreate(w http.ResponseWriter, r *http.Request) error {
418
419
if params .BanDuration != "none" {
419
420
duration , err = time .ParseDuration (params .BanDuration )
420
421
if err != nil {
421
- return badRequestError (ErrorCodeValidationFailed , "invalid format for ban duration: %v" , err )
422
+ return badRequestError (apierrors . ErrorCodeValidationFailed , "invalid format for ban duration: %v" , err )
422
423
}
423
424
}
424
425
banDuration = & duration
@@ -618,7 +619,7 @@ func (a *API) adminUserUpdateFactor(w http.ResponseWriter, r *http.Request) erro
618
619
if params .Phone != "" && factor .IsPhoneFactor () {
619
620
phone , err := validatePhone (params .Phone )
620
621
if err != nil {
621
- return badRequestError (ErrorCodeValidationFailed , "Invalid phone number format (E.164 required)" )
622
+ return badRequestError (apierrors . ErrorCodeValidationFailed , "Invalid phone number format (E.164 required)" )
622
623
}
623
624
if terr := factor .UpdatePhone (tx , phone ); terr != nil {
624
625
return terr
0 commit comments