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

Method UpdatePassword

internal/models/user.go:355–384  ·  view source on GitHub ↗

UpdatePassword updates the user's password. Use SetPassword outside of a transaction first!

(tx *storage.Connection, sessionID *uuid.UUID)

Source from the content-addressed store, hash-verified

353
354// UpdatePassword updates the user's password. Use SetPassword outside of a transaction first!
355func (u *User) UpdatePassword(tx *storage.Connection, sessionID *uuid.UUID) error {
356 // These need to be reset because password change may mean the user no longer trusts the actions performed by the previous password.
357 u.ConfirmationToken = ""
358 u.ConfirmationSentAt = nil
359 u.RecoveryToken = ""
360 u.RecoverySentAt = nil
361 u.EmailChangeTokenCurrent = ""
362 u.EmailChangeTokenNew = ""
363 u.EmailChangeSentAt = nil
364 u.PhoneChangeToken = ""
365 u.PhoneChangeSentAt = nil
366 u.ReauthenticationToken = ""
367 u.ReauthenticationSentAt = nil
368
369 if err := tx.UpdateOnly(u, "encrypted_password", "confirmation_token", "confirmation_sent_at", "recovery_token", "recovery_sent_at", "email_change_token_current", "email_change_token_new", "email_change_sent_at", "phone_change_token", "phone_change_sent_at", "reauthentication_token", "reauthentication_sent_at"); err != nil {
370 return err
371 }
372
373 if err := ClearAllOneTimeTokensForUser(tx, u.ID); err != nil {
374 return err
375 }
376
377 if sessionID == nil {
378 // log out user from all sessions to ensure reauthentication after password change
379 return Logout(tx, u.ID)
380 } else {
381 // log out user from all other sessions to ensure reauthentication after password change
382 return LogoutAllExceptMe(tx, *sessionID, u.ID)
383 }
384}
385
386// Authenticate a user from a password
387func (u *User) Authenticate(ctx context.Context, tx *storage.Connection, password string, decryptionKeys map[string]string, encrypt bool, encryptionKeyID string) (bool, bool, error) {

Callers 3

adminUserUpdateMethod · 0.80
signupVerifyMethod · 0.80
UserUpdateMethod · 0.80

Calls 4

LogoutFunction · 0.85
LogoutAllExceptMeFunction · 0.85
UpdateOnlyMethod · 0.80

Tested by

no test coverage detected