Auth interface Stay organized with collections Save and categorize content based on your preferences.
Interface representing Firebase Auth service.
SeeFirebase Authentication for a full guide on how to use the Firebase Auth service.
Signature:
exportinterfaceAuthProperties
| Property | Type | Description |
|---|---|---|
| app | FirebaseApp | TheFirebaseApp associated with theAuth service instance. |
| config | Config | TheConfig used to initialize this instance. |
| currentUser | User | null | The currently signed-in user (or null). |
| emulatorConfig | EmulatorConfig | null | The current emulator configuration (or null). |
| languageCode | string | null | TheAuth instance's language code. |
| name | string | The name of the app associated with theAuth service instance. |
| settings | AuthSettings | TheAuth instance's settings. |
| tenantId | string | null | TheAuth instance's tenant ID. |
Methods
| Method | Description |
|---|---|
| authStateReady() | returns a promise that resolves immediately when the initial auth state is settled. When the promise resolves, the current user might be a valid user ornull if the user signed out. |
| beforeAuthStateChanged(callback, onAbort) | Adds a blocking callback that runs before an auth state change sets a new user. |
| onAuthStateChanged(nextOrObserver, error, completed) | Adds an observer for changes to the user's sign-in state. |
| onIdTokenChanged(nextOrObserver, error, completed) | Adds an observer for changes to the signed-in user's ID token. |
| setPersistence(persistence) | Changes the type of persistence on theAuth instance. |
| signOut() | Signs out the current user. This does not automatically revoke the user's ID token. |
| updateCurrentUser(user) | Asynchronously sets the provided user asAuth.currentUser on theAuth instance. |
| useDeviceLanguage() | Sets the current language to the default device/browser preference. |
Auth.app
TheFirebaseApp associated with theAuth service instance.
Signature:
readonlyapp:FirebaseApp;Auth.config
TheConfig used to initialize this instance.
Signature:
readonlyconfig:Config;Auth.currentUser
The currently signed-in user (or null).
Signature:
readonlycurrentUser:User|null;Auth.emulatorConfig
The current emulator configuration (or null).
Signature:
readonlyemulatorConfig:EmulatorConfig|null;Auth.languageCode
TheAuth instance's language code.
This is a readable/writable property. When set to null, the default Firebase Console language setting is applied. The language code will propagate to email action templates (password reset, email verification and email change revocation), SMS templates for phone authentication, reCAPTCHA verifier and OAuth popup/redirect operations provided the specified providers support localization with the language code specified.
Signature:
languageCode:string|null;Auth.name
The name of the app associated with theAuth service instance.
Signature:
readonlyname:string;Auth.settings
TheAuth instance's settings.
This is used to edit/read configuration related options such as app verification mode for phone authentication.
Signature:
readonlysettings:AuthSettings;Auth.tenantId
TheAuth instance's tenant ID.
This is a readable/writable property. When you set the tenant ID of anAuth instance, all future sign-in/sign-up operations will pass this tenant ID and sign in or sign up users to the specified tenant project. When set to null, users are signed in to the parent project.
Signature:
tenantId:string|null;Example
// Set the tenant ID on Auth instance.auth.tenantId='TENANT_PROJECT_ID';// All future sign-in request now include tenant ID.constresult=awaitsignInWithEmailAndPassword(auth,email,password);// result.user.tenantId should be 'TENANT_PROJECT_ID'.Auth.authStateReady()
returns a promise that resolves immediately when the initial auth state is settled. When the promise resolves, the current user might be a valid user ornull if the user signed out.
Signature:
authStateReady():Promise<void>;Returns:
Promise<void>
Auth.beforeAuthStateChanged()
Adds a blocking callback that runs before an auth state change sets a new user.
Signature:
beforeAuthStateChanged(callback:(user:User|null)=>void|Promise<void>,onAbort?:()=>void):Unsubscribe;Parameters
| Parameter | Type | Description |
|---|---|---|
| callback | (user:User | null) => void | Promise<void> | callback triggered before new user value is set. If this throws, it blocks the user from being set. |
| onAbort | () => void | callback triggered if a laterbeforeAuthStateChanged() callback throws, allowing you to undo any side effects. |
Returns:
Auth.onAuthStateChanged()
Adds an observer for changes to the user's sign-in state.
To keep the old behavior, seeAuth.onIdTokenChanged().
Signature:
onAuthStateChanged(nextOrObserver:NextOrObserver<User|null>,error?:ErrorFn,completed?:CompleteFn):Unsubscribe;Parameters
| Parameter | Type | Description |
|---|---|---|
| nextOrObserver | NextOrObserver<User | null> | callback triggered on change. |
| error | ErrorFn | Deprecated. This callback is never triggered. Errors on signing in/out can be caught in promises returned from sign-in/sign-out functions. |
| completed | CompleteFn | Deprecated. This callback is never triggered. |
Returns:
Auth.onIdTokenChanged()
Adds an observer for changes to the signed-in user's ID token.
This includes sign-in, sign-out, and token refresh events.
Signature:
onIdTokenChanged(nextOrObserver:NextOrObserver<User|null>,error?:ErrorFn,completed?:CompleteFn):Unsubscribe;Parameters
| Parameter | Type | Description |
|---|---|---|
| nextOrObserver | NextOrObserver<User | null> | callback triggered on change. |
| error | ErrorFn | Deprecated. This callback is never triggered. Errors on signing in/out can be caught in promises returned from sign-in/sign-out functions. |
| completed | CompleteFn | Deprecated. This callback is never triggered. |
Returns:
Auth.setPersistence()
Changes the type of persistence on theAuth instance.
This will affect the currently saved Auth session and applies this type of persistence for future sign-in requests, including sign-in with redirect requests.
This makes it easy for a user signing in to specify whether their session should be remembered or not. It also makes it easier to never persist the Auth state for applications that are shared by other users or have sensitive data.
This method does not work in a Node.js environment.
Signature:
setPersistence(persistence:Persistence):Promise<void>;Parameters
| Parameter | Type | Description |
|---|---|---|
| persistence | Persistence | ThePersistence to use. |
Returns:
Promise<void>
Example
auth.setPersistence(browserSessionPersistence);Auth.signOut()
Signs out the current user. This does not automatically revoke the user's ID token.
This method is not supported byAuth instances created with aFirebaseServerApp.
Signature:
signOut():Promise<void>;Returns:
Promise<void>
Auth.updateCurrentUser()
Asynchronously sets the provided user asAuth.currentUser on theAuth instance.
A new instance copy of the user provided will be made and set as currentUser.
This will triggerAuth.onAuthStateChanged() andAuth.onIdTokenChanged() listeners like other sign in methods.
The operation fails with an error if the user to be updated belongs to a different Firebase project.
Signature:
updateCurrentUser(user:User|null):Promise<void>;Parameters
| Parameter | Type | Description |
|---|---|---|
| user | User | null | The newUser. |
Returns:
Promise<void>
Auth.useDeviceLanguage()
Sets the current language to the default device/browser preference.
Signature:
useDeviceLanguage():void;Returns:
void
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-03-28 UTC.