Skip to main content

Manage Users in Firebase

Notice

This page is archived and might not reflect the latest version of the FlutterFire plugins. You can find the latest information on firebase.google.com:

https://firebase.google.com/docs/auth/flutter/manage-users

Create a user#

You create a new user in your Firebase project in four ways:

  • Call the createUserWithEmailAndPassword() method.
  • Sign in a user for the first time using a federated identity provider, such as Google Sign-In, Facebook Login, or Apple.

You can also create new password-authenticated users from the Authentication section of the Firebase console, on the Users page.

Get a user's profile#

To get a user's profile information, use the properties of User. For example:

final user = FirebaseAuth.instance.currentUser;
if (user != null) {
// Name, email address, and profile photo URL
final name = user.displayName;
final email = user.email;
final photoUrl = user.photoURL;
// Check if user's email is verified
final emailVerified = user.emailVerified;
// The user's ID, unique to the Firebase project. Do NOT use this value to
// authenticate with your backend server, if you have one. Use
// User.getIdToken() instead.
final uid = user.uid;
}

Get a user's provider-specific profile information#

To get the profile information retrieved from the sign-in providers linked to a user, use the providerData property. For example:

if (user != null) {
for (final providerProfile in user.providerData) {
// ID of the provider (google.com, apple.cpm, etc.)
final provider = providerProfile.providerId;
// UID specific to the provider
final uid = providerProfile.uid;
// Name, email address, and profile photo URL
final name = providerProfile.displayName;
final emailAddress = providerProfile.email;
final profilePhoto = providerProfile.photoURL;
}
}

Update a user's profile#

You can update a user's basic profile information—the user's display name and profile photo URL—with the update- methods. For example:

await user?.updateDisplayName("Jane Q. User");
await user?.updatePhotoURL("https://example.com/jane-q-user/profile.jpg");

Set a user's email address#

You can set a user's email address with the updateEmail() method. For example:

await user?.updateEmail("janeq@example.com");
important

To set a user's email address, the user must have signed in recently. See Re-authenticate a user.

Send a user a verification email#

You can send an address verification email to a user with the sendEmailVerification() method. For example:

await user?.sendEmailVerification();

You can customize the email template that is used in Authentication section of the Firebase console, on the Email Templates page. See Email Templates in Firebase Help Center.

It is also possible to pass state via a continue URL to redirect back to the app when sending a verification email.

Additionally you can localize the verification email by updating the language code on the Auth instance before sending the email. For example:

await FirebaseAuth.instance.setLanguageCode("fr");
await user?.sendEmailVerification();

Set a user's password#

You can set a user's password with the updatePassword() method. For example:

await user?.updatePassword(newPassword);
important

To set a user's email address, the user must have signed in recently. See Re-authenticate a user.

Send a password reset email#

You can send a password reset email to a user with the sendPasswordResetEmail() method. For example:

await FirebaseAuth.instance
.sendPasswordResetEmail(email: "user@example.com");

You can customize the email template that is used in Authentication section of the Firebase console, on the Email Templates page. See Email Templates in Firebase Help Center.

It is also possible to pass state via a continue URL to redirect back to the app when sending a password reset email.

Additionally you can localize the password reset email by updating the language code on the Auth instance before sending the email. For example:

await FirebaseAuth.instance.setLanguageCode("fr");

You can also send password reset emails from the Firebase console.

Delete a user#

You can delete a user account with the delete() method. For example:

await user?.delete();
important

To set a user's email address, the user must have signed in recently. See Re-authenticate a user.

You can also delete users from the Authentication section of the Firebase console, on the Users page.

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 and throws a FirebaseAuthException with the code requires-recent-login. When this happens, re-authenticate the user by getting new sign-in credentials from the user and passing the credentials to reauthenticate. For example:

// Prompt the user to re-provide their sign-in credentials.
// Then, use the credentials to reauthenticate:
await user?.reauthenticateWithCredential(credential);

Import user accounts#

You can import user accounts from a file into your Firebase project by using the Firebase CLI's auth:import command. For example:

firebase auth:import users.json --hash-algo=scrypt --rounds=8 --mem-cost=14