Manage Users in Firebase

Create a user

You create a new user in your Firebase project by calling the createUserWithEmailAndPassword method or by signing in a user for the first time using a federated identity provider, such as Google Sign-In or Facebook Login.

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

Get the currently signed-in user

The recommended way to get the current user is by setting an observer on the Auth object:

firebase.auth().onAuthStateChanged(function(user) {
  if (user) {
    // User is signed in.
  } else {
    // No user is signed in.
  }
});

By using an observer, you ensure that the Auth object isn't in an intermediate state—such as initialization—when you get the current user. When you use signInWithRedirect, the onAuthStateChanged observer waits until getRedirectResult resolves before triggering.

You can also get the currently signed-in user by using the currentUser property. If a user isn't signed in, currentUser is null:

var user = firebase.auth().currentUser;

if (user) {
  // User is signed in.
} else {
  // No user is signed in.
}

Get a user's profile

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

var user = firebase.auth().currentUser;
var name, email, photoUrl, uid, emailVerified;

if (user != null) {
  name = user.displayName;
  email = user.email;
  photoUrl = user.photoURL;
  emailVerified = user.emailVerified;
  uid = user.uid;  // 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.getToken() instead.
}

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:

var user = firebase.auth().currentUser;

if (user != null) {
  user.providerData.forEach(function (profile) {
    console.log("Sign-in provider: "+profile.providerId);
    console.log("  Provider-specific UID: "+profile.uid);
    console.log("  Name: "+profile.displayName);
    console.log("  Email: "+profile.email);
    console.log("  Photo URL: "+profile.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 updateProfile method. For example:

var user = firebase.auth().currentUser;

user.updateProfile({
  displayName: "Jane Q. User",
  photoURL: "https://example.com/jane-q-user/profile.jpg"
}).then(function() {
  // Update successful.
}).catch(function(error) {
  // An error happened.
});

Set a user's email address

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

var user = firebase.auth().currentUser;

user.updateEmail("user@example.com").then(function() {
  // Update successful.
}).catch(function(error) {
  // An error happened.
});

Send a user a verification email

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

var user = firebase.auth().currentUser;

user.sendEmailVerification().then(function() {
  // Email sent.
}).catch(function(error) {
  // An error happened.
});

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:

firebase.auth().languageCode = 'fr';
// To apply the default browser preference instead of explicitly setting it.
// firebase.auth().useDeviceLanguage();

Set a user's password

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

var user = firebase.auth().currentUser;
var newPassword = getASecureRandomPassword();

user.updatePassword(newPassword).then(function() {
  // Update successful.
}).catch(function(error) {
  // An error happened.
});

Send a password reset email

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

var auth = firebase.auth();
var emailAddress = "user@example.com";

auth.sendPasswordResetEmail(emailAddress).then(function() {
  // Email sent.
}).catch(function(error) {
  // An error happened.
});

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:

firebase.auth().languageCode = 'de';
// To apply the default browser preference instead of explicitly setting it.
// firebase.auth().useDeviceLanguage();

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:

var user = firebase.auth().currentUser;

user.delete().then(function() {
  // User deleted.
}).catch(function(error) {
  // An error happened.
});

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 with an error. When this happens, re-authenticate the user by getting new sign-in credentials from the user and passing the credentials to reauthenticateWithCredential. For example:

var user = firebase.auth().currentUser;
var credential;

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

user.reauthenticateWithCredential(credential).then(function() {
  // User re-authenticated.
}).catch(function(error) {
  // An error happened.
});

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

Send feedback about...

Need help? Visit our support page.