简体   繁体   中英

FirebaseAuth - Replication of a modifed user login/email

Changing the email address of the currently logged in user works just fine using the updateEmail method of the user object, however it appears as if that change is not replicated to other logins, which still keep the previous email address.

Is there any notification I need to subscribe to / catch in order to be notified by such a change or is there another way to accomplish that?

Me, as a long time Firebaser, I read the docs a lot, like a lot. And I do have a workaround for this since there aren't any built in.

First, if you provide multiple sessions per user, you'd want to use the reauthenticate method.

Re-authenticate a user

Some security-sensitive actions—such as deleting an account, setting a primary email address, and changing a password—require that the user has recently signed in. If you perform one of these actions, and the user signed in too long ago, the action fails with the FIRAuthErrorCodeCredentialTooOld error. When this happens, re-authenticate the user by getting new sign-in credentials from the user and passing the credentials to reauthenticate. For example:

let user = Auth.auth().currentUser
var credential: AuthCredential

// Prompt the user to re-provide their sign-in credentials

user?.reauthenticate(with: credential) { error in
  if let error = error {
// An error happened.
  } else {
// User re-authenticated.
  }
}

Using this, you'd get the error 90% percent of the time because of old credentials.

Or:

(1) On the change process. Set a specific key for the user on your real-time database or Firestore, (2) Check for that specific key on your app, if existed. That means the user needs to be re authenticated. Firebase will update the user credential on every new login.

I hope it helps. Here's the docs:

Manage users on Firebase

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM