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

Method smsVerify

internal/api/verify.go:402–481  ·  view source on GitHub ↗
(r *http.Request, conn *storage.Connection, user *models.User, params *VerifyParams)

Source from the content-addressed store, hash-verified

400}
401
402func (a *API) smsVerify(r *http.Request, conn *storage.Connection, user *models.User, params *VerifyParams) (*models.User, error) {
403 config := a.config
404
405 oldPhone := user.GetPhone()
406 phoneIdentityWasCreated := false
407 err := conn.Transaction(func(tx *storage.Connection) error {
408
409 if params.Type == smsVerification {
410 if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.UserSignedUpAction, "", map[string]interface{}{
411 "provider": PhoneProvider,
412 }); terr != nil {
413 return terr
414 }
415 if terr := user.ConfirmPhone(tx); terr != nil {
416 return apierrors.NewInternalServerError("Error confirming user").WithInternalError(terr)
417 }
418 } else if params.Type == phoneChangeVerification {
419 if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.UserModifiedAction, "", nil); terr != nil {
420 return terr
421 }
422 if identity, terr := models.FindIdentityByIdAndProvider(tx, user.ID.String(), "phone"); terr != nil {
423 if !models.IsNotFoundError(terr) {
424 return terr
425 }
426 // confirming the phone change should create a new phone identity if the user doesn't have one
427 if _, terr = a.createNewIdentity(tx, user, "phone", structs.Map(provider.Claims{
428 Subject: user.ID.String(),
429 Phone: params.Phone,
430 PhoneVerified: true,
431 })); terr != nil {
432 return terr
433 }
434 phoneIdentityWasCreated = true
435 } else {
436 if terr := identity.UpdateIdentityData(tx, map[string]interface{}{
437 "phone": params.Phone,
438 "phone_verified": true,
439 }); terr != nil {
440 return terr
441 }
442 }
443 if terr := user.ConfirmPhoneChange(tx); terr != nil {
444 return apierrors.NewInternalServerError("Error confirming user").WithInternalError(terr)
445 }
446 }
447
448 if user.IsAnonymous {
449 user.IsAnonymous = false
450 if terr := tx.UpdateOnly(user, "is_anonymous"); terr != nil {
451 return terr
452 }
453 }
454
455 if terr := tx.Load(user, "Identities"); terr != nil {
456 return apierrors.NewInternalServerError("Error refetching identities").WithInternalError(terr)
457 }
458 return nil
459 })

Callers 2

verifyPostMethod · 0.95
UserUpdateMethod · 0.95

Calls 15

createNewIdentityMethod · 0.95
NewAuditLogEntryFunction · 0.92
NewInternalServerErrorFunction · 0.92
IsNotFoundErrorFunction · 0.92
phoneNumberChangedFunction · 0.85
GetPhoneMethod · 0.80
TransactionMethod · 0.80
ConfirmPhoneMethod · 0.80
UpdateIdentityDataMethod · 0.80

Tested by

no test coverage detected