UNPKG

firebase

Version:

Firebase JavaScript library for web and Node.js

1,227 lines (1,190 loc) 392 kB
/** * @license * Copyright 2021 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * <code>firebase</code> is a global namespace from which all Firebase * services are accessed. */ declare namespace firebase { /** * @hidden */ type NextFn<T> = (value: T) => void; /** * @hidden */ type ErrorFn<E = Error> = (error: E) => void; /** * @hidden */ type CompleteFn = () => void; /** * `FirebaseError` is a subclass of the standard JavaScript `Error` object. In * addition to a message string and stack trace, it contains a string code. */ interface FirebaseError { /** * Error codes are strings using the following format: `"service/string-code"`. * Some examples include `"app/no-app"` and `"auth/user-not-found"`. * * While the message for a given error can change, the code will remain the same * between backward-compatible versions of the Firebase SDK. */ code: string; /** * An explanatory message for the error that just occurred. * * This message is designed to be helpful to you, the developer. Because * it generally does not convey meaningful information to end users, * this message should not be displayed in your application. */ message: string; /** * The name of the class of errors, which is `"FirebaseError"`. */ name: 'FirebaseError'; /** * A string value containing the execution backtrace when the error originally * occurred. This may not always be available. * * When it is available, this information can be sent to * {@link https://firebase.google.com/support/ Firebase Support} to help * explain the cause of an error. */ stack?: string; } /** * @hidden */ interface Observer<T, E = Error> { next: NextFn<T>; error: ErrorFn<E>; complete: CompleteFn; } /** * The JS SDK supports 5 log levels and also allows a user the ability to * silence the logs altogether. * * The order is as follows: * silent < debug < verbose < info < warn < error */ type LogLevel = 'debug' | 'verbose' | 'info' | 'warn' | 'error' | 'silent'; /** * The current SDK version. */ var SDK_VERSION: string; /** * Registers a library's name and version for platform logging purposes. * @param library Name of 1p or 3p library (e.g. firestore, angularfire) * @param version Current version of that library. * @param variant Bundle variant, e.g., node, rn, etc. */ function registerVersion( library: string, version: string, variant?: string ): void; /** * Sets log level for all Firebase packages. * * All of the log types above the current log level are captured (i.e. if * you set the log level to `info`, errors are logged, but `debug` and * `verbose` logs are not). */ function setLogLevel(logLevel: LogLevel): void; /** * Sets log handler for all Firebase packages. * @param logCallback An optional custom log handler that executes user code whenever * the Firebase SDK makes a logging call. */ function onLog( logCallback: (callbackParams: { /** * Level of event logged. */ level: LogLevel; /** * Any text from logged arguments joined into one string. */ message: string; /** * The raw arguments passed to the log call. */ args: any[]; /** * A string indicating the name of the package that made the log call, * such as `@firebase/firestore`. */ type: string; }) => void, options?: { /** * Threshhold log level. Only logs at or above this level trigger the `logCallback` * passed to `onLog`. */ level: LogLevel; } ): void; /** * @hidden */ type Unsubscribe = () => void; /** * A user account. */ interface User extends firebase.UserInfo { /** * Deletes and signs out the user. * * <b>Important:</b> this is a security-sensitive operation that requires the * user to have recently signed in. If this requirement isn't met, ask the user * to authenticate again and then call * {@link firebase.User.reauthenticateWithCredential}. * * <h4>Error Codes</h4> * <dl> * <dt>auth/requires-recent-login</dt> * <dd>Thrown if the user's last sign-in time does not meet the security * threshold. Use {@link firebase.User.reauthenticateWithCredential} to * resolve. This does not apply if the user is anonymous.</dd> * </dl> */ delete(): Promise<void>; emailVerified: boolean; getIdTokenResult( forceRefresh?: boolean ): Promise<firebase.auth.IdTokenResult>; /** * Returns a JSON Web Token (JWT) used to identify the user to a Firebase * service. * * Returns the current token if it has not expired. Otherwise, this will * refresh the token and return a new one. * * @param forceRefresh Force refresh regardless of token * expiration. */ getIdToken(forceRefresh?: boolean): Promise<string>; isAnonymous: boolean; /** * Links the user account with the given credentials and returns any available * additional user information, such as user name. * * <h4>Error Codes</h4> * <dl> * <dt>auth/provider-already-linked</dt> * <dd>Thrown if the provider has already been linked to the user. This error is * thrown even if this is not the same provider's account that is currently * linked to the user.</dd> * <dt>auth/invalid-credential</dt> * <dd>Thrown if the provider's credential is not valid. This can happen if it * has already expired when calling link, or if it used invalid token(s). * See the Firebase documentation for your provider, and make sure you pass * in the correct parameters to the credential method.</dd> * <dt>auth/credential-already-in-use</dt> * <dd>Thrown if the account corresponding to the credential already exists * among your users, or is already linked to a Firebase User. * For example, this error could be thrown if you are upgrading an anonymous * user to a Google user by linking a Google credential to it and the Google * credential used is already associated with an existing Firebase Google * user. * The fields <code>error.email</code>, <code>error.phoneNumber</code>, and * <code>error.credential</code> ({@link firebase.auth.AuthCredential}) * may be provided, depending on the type of credential. You can recover * from this error by signing in with <code>error.credential</code> directly * via {@link firebase.auth.Auth.signInWithCredential}.</dd> * <dt>auth/email-already-in-use</dt> * <dd>Thrown if the email corresponding to the credential already exists * among your users. When thrown while linking a credential to an existing * user, an <code>error.email</code> and <code>error.credential</code> * ({@link firebase.auth.AuthCredential}) fields are also provided. * You have to link the credential to the existing user with that email if * you wish to continue signing in with that credential. To do so, call * {@link firebase.auth.Auth.fetchSignInMethodsForEmail}, sign in to * <code>error.email</code> via one of the providers returned and then * {@link firebase.User.linkWithCredential} the original credential to that * newly signed in user.</dd> * <dt>auth/operation-not-allowed</dt> * <dd>Thrown if you have not enabled the provider in the Firebase Console. Go * to the Firebase Console for your project, in the Auth section and the * <strong>Sign in Method</strong> tab and configure the provider.</dd> * <dt>auth/invalid-email</dt> * <dd>Thrown if the email used in a * {@link firebase.auth.EmailAuthProvider.credential} is invalid.</dd> * <dt>auth/wrong-password</dt> * <dd>Thrown if the password used in a * {@link firebase.auth.EmailAuthProvider.credential} is not correct or * when the user associated with the email does not have a password.</dd> * <dt>auth/invalid-verification-code</dt> * <dd>Thrown if the credential is a * {@link firebase.auth.PhoneAuthProvider.credential} and the verification * code of the credential is not valid.</dd> * <dt>auth/invalid-verification-id</dt> * <dd>Thrown if the credential is a * {@link firebase.auth.PhoneAuthProvider.credential} and the verification * ID of the credential is not valid.</dd> * </dl> * * @deprecated This method is deprecated. Use * {@link firebase.User.linkWithCredential} instead. * * @param credential The auth credential. */ linkAndRetrieveDataWithCredential( credential: firebase.auth.AuthCredential ): Promise<firebase.auth.UserCredential>; /** * Links the user account with the given credentials. * * <h4>Error Codes</h4> * <dl> * <dt>auth/provider-already-linked</dt> * <dd>Thrown if the provider has already been linked to the user. This error is * thrown even if this is not the same provider's account that is currently * linked to the user.</dd> * <dt>auth/invalid-credential</dt> * <dd>Thrown if the provider's credential is not valid. This can happen if it * has already expired when calling link, or if it used invalid token(s). * See the Firebase documentation for your provider, and make sure you pass * in the correct parameters to the credential method.</dd> * <dt>auth/credential-already-in-use</dt> * <dd>Thrown if the account corresponding to the credential already exists * among your users, or is already linked to a Firebase User. * For example, this error could be thrown if you are upgrading an anonymous * user to a Google user by linking a Google credential to it and the Google * credential used is already associated with an existing Firebase Google * user. * The fields <code>error.email</code>, <code>error.phoneNumber</code>, and * <code>error.credential</code> ({@link firebase.auth.AuthCredential}) * may be provided, depending on the type of credential. You can recover * from this error by signing in with <code>error.credential</code> directly * via {@link firebase.auth.Auth.signInWithCredential}.</dd> * <dt>auth/email-already-in-use</dt> * <dd>Thrown if the email corresponding to the credential already exists * among your users. When thrown while linking a credential to an existing * user, an <code>error.email</code> and <code>error.credential</code> * ({@link firebase.auth.AuthCredential}) fields are also provided. * You have to link the credential to the existing user with that email if * you wish to continue signing in with that credential. To do so, call * {@link firebase.auth.Auth.fetchSignInMethodsForEmail}, sign in to * <code>error.email</code> via one of the providers returned and then * {@link firebase.User.linkWithCredential} the original credential to that * newly signed in user.</dd> * <dt>auth/operation-not-allowed</dt> * <dd>Thrown if you have not enabled the provider in the Firebase Console. Go * to the Firebase Console for your project, in the Auth section and the * <strong>Sign in Method</strong> tab and configure the provider.</dd> * <dt>auth/invalid-email</dt> * <dd>Thrown if the email used in a * {@link firebase.auth.EmailAuthProvider.credential} is invalid.</dd> * <dt>auth/wrong-password</dt> * <dd>Thrown if the password used in a * {@link firebase.auth.EmailAuthProvider.credential} is not correct or * when the user associated with the email does not have a password.</dd> * <dt>auth/invalid-verification-code</dt> * <dd>Thrown if the credential is a * {@link firebase.auth.PhoneAuthProvider.credential} and the verification * code of the credential is not valid.</dd> * <dt>auth/invalid-verification-id</dt> * <dd>Thrown if the credential is a * {@link firebase.auth.PhoneAuthProvider.credential} and the verification * ID of the credential is not valid.</dd> * </dl> * * @param credential The auth credential. */ linkWithCredential( credential: firebase.auth.AuthCredential ): Promise<firebase.auth.UserCredential>; /** * Links the user account with the given phone number. * * <h4>Error Codes</h4> * <dl> * <dt>auth/provider-already-linked</dt> * <dd>Thrown if the provider has already been linked to the user. This error is * thrown even if this is not the same provider's account that is currently * linked to the user.</dd> * <dt>auth/captcha-check-failed</dt> * <dd>Thrown if the reCAPTCHA response token was invalid, expired, or if * this method was called from a non-whitelisted domain.</dd> * <dt>auth/invalid-phone-number</dt> * <dd>Thrown if the phone number has an invalid format.</dd> * <dt>auth/missing-phone-number</dt> * <dd>Thrown if the phone number is missing.</dd> * <dt>auth/quota-exceeded</dt> * <dd>Thrown if the SMS quota for the Firebase project has been exceeded.</dd> * <dt>auth/user-disabled</dt> * <dd>Thrown if the user corresponding to the given phone number has been * disabled.</dd> * <dt>auth/credential-already-in-use</dt> * <dd>Thrown if the account corresponding to the phone number already exists * among your users, or is already linked to a Firebase User. * The fields <code>error.phoneNumber</code> and * <code>error.credential</code> ({@link firebase.auth.AuthCredential}) * are provided in this case. You can recover from this error by signing in * with that credential directly via * {@link firebase.auth.Auth.signInWithCredential}.</dd> * <dt>auth/operation-not-allowed</dt> * <dd>Thrown if you have not enabled the phone authentication provider in the * Firebase Console. Go to the Firebase Console for your project, in the * Auth section and the <strong>Sign in Method</strong> tab and configure * the provider.</dd> * </dl> * * @param phoneNumber The user's phone number in E.164 format (e.g. * +16505550101). * @param applicationVerifier */ linkWithPhoneNumber( phoneNumber: string, applicationVerifier: firebase.auth.ApplicationVerifier ): Promise<firebase.auth.ConfirmationResult>; /** * Links the authenticated provider to the user account using a pop-up based * OAuth flow. * * If the linking is successful, the returned result will contain the user * and the provider's credential. * * <h4>Error Codes</h4> * <dl> * <dt>auth/auth-domain-config-required</dt> * <dd>Thrown if authDomain configuration is not provided when calling * firebase.initializeApp(). Check Firebase Console for instructions on * determining and passing that field.</dd> * <dt>auth/cancelled-popup-request</dt> * <dd>Thrown if successive popup operations are triggered. Only one popup * request is allowed at one time on a user or an auth instance. All the * popups would fail with this error except for the last one.</dd> * <dt>auth/credential-already-in-use</dt> * <dd>Thrown if the account corresponding to the credential already exists * among your users, or is already linked to a Firebase User. * For example, this error could be thrown if you are upgrading an anonymous * user to a Google user by linking a Google credential to it and the Google * credential used is already associated with an existing Firebase Google * user. * An <code>error.email</code> and <code>error.credential</code> * ({@link firebase.auth.AuthCredential}) fields are also provided. You can * recover from this error by signing in with that credential directly via * {@link firebase.auth.Auth.signInWithCredential}.</dd> * <dt>auth/email-already-in-use</dt> * <dd>Thrown if the email corresponding to the credential already exists * among your users. When thrown while linking a credential to an existing * user, an <code>error.email</code> and <code>error.credential</code> * ({@link firebase.auth.AuthCredential}) fields are also provided. * You have to link the credential to the existing user with that email if * you wish to continue signing in with that credential. To do so, call * {@link firebase.auth.Auth.fetchSignInMethodsForEmail}, sign in to * <code>error.email</code> via one of the providers returned and then * {@link firebase.User.linkWithCredential} the original credential to that * newly signed in user.</dd> * <dt>auth/operation-not-allowed</dt> * <dd>Thrown if you have not enabled the provider in the Firebase Console. Go * to the Firebase Console for your project, in the Auth section and the * <strong>Sign in Method</strong> tab and configure the provider.</dd> * <dt>auth/popup-blocked</dt> * <dt>auth/operation-not-supported-in-this-environment</dt> * <dd>Thrown if this operation is not supported in the environment your * application is running on. "location.protocol" must be http or https. * </dd> * <dd>Thrown if the popup was blocked by the browser, typically when this * operation is triggered outside of a click handler.</dd> * <dt>auth/popup-closed-by-user</dt> * <dd>Thrown if the popup window is closed by the user without completing the * sign in to the provider.</dd> * <dt>auth/provider-already-linked</dt> * <dd>Thrown if the provider has already been linked to the user. This error is * thrown even if this is not the same provider's account that is currently * linked to the user.</dd> * <dt>auth/unauthorized-domain</dt> * <dd>Thrown if the app domain is not authorized for OAuth operations for your * Firebase project. Edit the list of authorized domains from the Firebase * console.</dd> * </dl> * * This method does not work in a Node.js environment. * * @example * ```javascript * // Creates the provider object. * var provider = new firebase.auth.FacebookAuthProvider(); * // You can add additional scopes to the provider: * provider.addScope('email'); * provider.addScope('user_friends'); * // Link with popup: * user.linkWithPopup(provider).then(function(result) { * // The firebase.User instance: * var user = result.user; * // The Facebook firebase.auth.AuthCredential containing the Facebook * // access token: * var credential = result.credential; * }, function(error) { * // An error happened. * }); * ``` * * @param provider The provider to authenticate. * The provider has to be an OAuth provider. Non-OAuth providers like {@link * firebase.auth.EmailAuthProvider} will throw an error. */ linkWithPopup( provider: firebase.auth.AuthProvider ): Promise<firebase.auth.UserCredential>; /** * Links the authenticated provider to the user account using a full-page * redirect flow. * * <h4>Error Codes</h4> * <dl> * <dt>auth/auth-domain-config-required</dt> * <dd>Thrown if authDomain configuration is not provided when calling * firebase.initializeApp(). Check Firebase Console for instructions on * determining and passing that field.</dd> * <dt>auth/operation-not-supported-in-this-environment</dt> * <dd>Thrown if this operation is not supported in the environment your * application is running on. "location.protocol" must be http or https. * </dd> * <dt>auth/provider-already-linked</dt> * <dd>Thrown if the provider has already been linked to the user. This error is * thrown even if this is not the same provider's account that is currently * linked to the user.</dd> * <dt>auth/unauthorized-domain</dt> * <dd>Thrown if the app domain is not authorized for OAuth operations for your * Firebase project. Edit the list of authorized domains from the Firebase * console.</dd> * </dl> * * @param provider The provider to authenticate. * The provider has to be an OAuth provider. Non-OAuth providers like {@link * firebase.auth.EmailAuthProvider} will throw an error. */ linkWithRedirect(provider: firebase.auth.AuthProvider): Promise<void>; metadata: firebase.auth.UserMetadata; /** * The {@link firebase.User.MultiFactorUser} object corresponding to the current user. * This is used to access all multi-factor properties and operations related to the * current user. */ multiFactor: firebase.User.MultiFactorUser; /** * The phone number normalized based on the E.164 standard (e.g. +16505550101) * for the current user. This is null if the user has no phone credential linked * to the account. */ phoneNumber: string | null; providerData: (firebase.UserInfo | null)[]; /** * Re-authenticates a user using a fresh credential, and returns any available * additional user information, such as user name. Use before operations * such as {@link firebase.User.updatePassword} that require tokens from recent * sign-in attempts. * * <h4>Error Codes</h4> * <dl> * <dt>auth/user-mismatch</dt> * <dd>Thrown if the credential given does not correspond to the user.</dd> * <dt>auth/user-not-found</dt> * <dd>Thrown if the credential given does not correspond to any existing user. * </dd> * <dt>auth/invalid-credential</dt> * <dd>Thrown if the provider's credential is not valid. This can happen if it * has already expired when calling link, or if it used invalid token(s). * See the Firebase documentation for your provider, and make sure you pass * in the correct parameters to the credential method.</dd> * <dt>auth/invalid-email</dt> * <dd>Thrown if the email used in a * {@link firebase.auth.EmailAuthProvider.credential} is invalid.</dd> * <dt>auth/wrong-password</dt> * <dd>Thrown if the password used in a * {@link firebase.auth.EmailAuthProvider.credential} is not correct or when * the user associated with the email does not have a password.</dd> * <dt>auth/invalid-verification-code</dt> * <dd>Thrown if the credential is a * {@link firebase.auth.PhoneAuthProvider.credential} and the verification * code of the credential is not valid.</dd> * <dt>auth/invalid-verification-id</dt> * <dd>Thrown if the credential is a * {@link firebase.auth.PhoneAuthProvider.credential} and the verification * ID of the credential is not valid.</dd> * </dl> * * @deprecated * This method is deprecated. Use * {@link firebase.User.reauthenticateWithCredential} instead. * * @param credential */ reauthenticateAndRetrieveDataWithCredential( credential: firebase.auth.AuthCredential ): Promise<firebase.auth.UserCredential>; /** * Re-authenticates a user using a fresh credential. Use before operations * such as {@link firebase.User.updatePassword} that require tokens from recent * sign-in attempts. * * <h4>Error Codes</h4> * <dl> * <dt>auth/user-mismatch</dt> * <dd>Thrown if the credential given does not correspond to the user.</dd> * <dt>auth/user-not-found</dt> * <dd>Thrown if the credential given does not correspond to any existing user. * </dd> * <dt>auth/invalid-credential</dt> * <dd>Thrown if the provider's credential is not valid. This can happen if it * has already expired when calling link, or if it used invalid token(s). * See the Firebase documentation for your provider, and make sure you pass * in the correct parameters to the credential method.</dd> * <dt>auth/invalid-email</dt> * <dd>Thrown if the email used in a * {@link firebase.auth.EmailAuthProvider.credential} is invalid.</dd> * <dt>auth/wrong-password</dt> * <dd>Thrown if the password used in a * {@link firebase.auth.EmailAuthProvider.credential} is not correct or when * the user associated with the email does not have a password.</dd> * <dt>auth/invalid-verification-code</dt> * <dd>Thrown if the credential is a * {@link firebase.auth.PhoneAuthProvider.credential} and the verification * code of the credential is not valid.</dd> * <dt>auth/invalid-verification-id</dt> * <dd>Thrown if the credential is a * {@link firebase.auth.PhoneAuthProvider.credential} and the verification * ID of the credential is not valid.</dd> * </dl> * * @param credential */ reauthenticateWithCredential( credential: firebase.auth.AuthCredential ): Promise<firebase.auth.UserCredential>; /** * Re-authenticates a user using a fresh credential. Use before operations * such as {@link firebase.User.updatePassword} that require tokens from recent * sign-in attempts. * * <h4>Error Codes</h4> * <dl> * <dt>auth/user-mismatch</dt> * <dd>Thrown if the credential given does not correspond to the user.</dd> * <dt>auth/user-not-found</dt> * <dd>Thrown if the credential given does not correspond to any existing user. * </dd> * <dt>auth/captcha-check-failed</dt> * <dd>Thrown if the reCAPTCHA response token was invalid, expired, or if * this method was called from a non-whitelisted domain.</dd> * <dt>auth/invalid-phone-number</dt> * <dd>Thrown if the phone number has an invalid format.</dd> * <dt>auth/missing-phone-number</dt> * <dd>Thrown if the phone number is missing.</dd> * <dt>auth/quota-exceeded</dt> * <dd>Thrown if the SMS quota for the Firebase project has been exceeded.</dd> * </dl> * * @param phoneNumber The user's phone number in E.164 format (e.g. * +16505550101). * @param applicationVerifier */ reauthenticateWithPhoneNumber( phoneNumber: string, applicationVerifier: firebase.auth.ApplicationVerifier ): Promise<firebase.auth.ConfirmationResult>; /** * Reauthenticates the current user with the specified provider using a pop-up * based OAuth flow. * * If the reauthentication is successful, the returned result will contain the * user and the provider's credential. * * <h4>Error Codes</h4> * <dl> * <dt>auth/auth-domain-config-required</dt> * <dd>Thrown if authDomain configuration is not provided when calling * firebase.initializeApp(). Check Firebase Console for instructions on * determining and passing that field.</dd> * <dt>auth/cancelled-popup-request</dt> * <dd>Thrown if successive popup operations are triggered. Only one popup * request is allowed at one time on a user or an auth instance. All the * popups would fail with this error except for the last one.</dd> * <dt>auth/user-mismatch</dt> * <dd>Thrown if the credential given does not correspond to the user.</dd> * <dt>auth/operation-not-allowed</dt> * <dd>Thrown if you have not enabled the provider in the Firebase Console. Go * to the Firebase Console for your project, in the Auth section and the * <strong>Sign in Method</strong> tab and configure the provider.</dd> * <dt>auth/popup-blocked</dt> * <dd>Thrown if the popup was blocked by the browser, typically when this * operation is triggered outside of a click handler.</dd> * <dt>auth/operation-not-supported-in-this-environment</dt> * <dd>Thrown if this operation is not supported in the environment your * application is running on. "location.protocol" must be http or https. * </dd> * <dt>auth/popup-closed-by-user</dt> * <dd>Thrown if the popup window is closed by the user without completing the * sign in to the provider.</dd> * <dt>auth/unauthorized-domain</dt> * <dd>Thrown if the app domain is not authorized for OAuth operations for your * Firebase project. Edit the list of authorized domains from the Firebase * console.</dd> * </dl> * * This method does not work in a Node.js environment. * * @example * ```javascript * // Creates the provider object. * var provider = new firebase.auth.FacebookAuthProvider(); * // You can add additional scopes to the provider: * provider.addScope('email'); * provider.addScope('user_friends'); * // Reauthenticate with popup: * user.reauthenticateWithPopup(provider).then(function(result) { * // The firebase.User instance: * var user = result.user; * // The Facebook firebase.auth.AuthCredential containing the Facebook * // access token: * var credential = result.credential; * }, function(error) { * // An error happened. * }); * ``` * * @param provider The provider to authenticate. * The provider has to be an OAuth provider. Non-OAuth providers like {@link * firebase.auth.EmailAuthProvider} will throw an error. */ reauthenticateWithPopup( provider: firebase.auth.AuthProvider ): Promise<firebase.auth.UserCredential>; /** * Reauthenticates the current user with the specified OAuth provider using a * full-page redirect flow. * * <h4>Error Codes</h4> * <dl> * <dt>auth/auth-domain-config-required</dt> * <dd>Thrown if authDomain configuration is not provided when calling * firebase.initializeApp(). Check Firebase Console for instructions on * determining and passing that field.</dd> * <dt>auth/operation-not-supported-in-this-environment</dt> * <dd>Thrown if this operation is not supported in the environment your * application is running on. "location.protocol" must be http or https. * </dd> * <dt>auth/user-mismatch</dt> * <dd>Thrown if the credential given does not correspond to the user.</dd> * <dt>auth/unauthorized-domain</dt> * <dd>Thrown if the app domain is not authorized for OAuth operations for your * Firebase project. Edit the list of authorized domains from the Firebase * console.</dd> * </dl> * * This method does not work in a Node.js environment. * * @param provider The provider to authenticate. * The provider has to be an OAuth provider. Non-OAuth providers like {@link * firebase.auth.EmailAuthProvider} will throw an error. */ reauthenticateWithRedirect( provider: firebase.auth.AuthProvider ): Promise<void>; refreshToken: string; /** * Refreshes the current user, if signed in. * */ reload(): Promise<void>; /** * Sends a verification email to a user. * * The verification process is completed by calling * {@link firebase.auth.Auth.applyActionCode} * * <h4>Error Codes</h4> * <dl> * <dt>auth/missing-android-pkg-name</dt> * <dd>An Android package name must be provided if the Android app is required * to be installed.</dd> * <dt>auth/missing-continue-uri</dt> * <dd>A continue URL must be provided in the request.</dd> * <dt>auth/missing-ios-bundle-id</dt> * <dd>An iOS bundle ID must be provided if an App Store ID is provided.</dd> * <dt>auth/invalid-continue-uri</dt> * <dd>The continue URL provided in the request is invalid.</dd> * <dt>auth/unauthorized-continue-uri</dt> * <dd>The domain of the continue URL is not whitelisted. Whitelist * the domain in the Firebase console.</dd> * </dl> * * @example * ```javascript * var actionCodeSettings = { * url: 'https://www.example.com/cart?email=user@example.com&cartId=123', * iOS: { * bundleId: 'com.example.ios' * }, * android: { * packageName: 'com.example.android', * installApp: true, * minimumVersion: '12' * }, * handleCodeInApp: true * }; * firebase.auth().currentUser.sendEmailVerification(actionCodeSettings) * .then(function() { * // Verification email sent. * }) * .catch(function(error) { * // Error occurred. Inspect error.code. * }); * ``` * * @param actionCodeSettings The action * code settings. If specified, the state/continue URL will be set as the * "continueUrl" parameter in the email verification link. The default email * verification landing page will use this to display a link to go back to * the app if it is installed. * If the actionCodeSettings is not specified, no URL is appended to the * action URL. * The state URL provided must belong to a domain that is whitelisted by the * developer in the console. Otherwise an error will be thrown. * Mobile app redirects will only be applicable if the developer configures * and accepts the Firebase Dynamic Links terms of condition. * The Android package name and iOS bundle ID will be respected only if they * are configured in the same Firebase Auth project used. */ sendEmailVerification( actionCodeSettings?: firebase.auth.ActionCodeSettings | null ): Promise<void>; /** * The current user's tenant ID. This is a read-only property, which indicates * the tenant ID used to sign in the current user. This is null if the user is * signed in from the parent project. * * @example * ```javascript * // Set the tenant ID on Auth instance. * firebase.auth().tenantId = ‘TENANT_PROJECT_ID’; * * // All future sign-in request now include tenant ID. * firebase.auth().signInWithEmailAndPassword(email, password) * .then(function(result) { * // result.user.tenantId should be ‘TENANT_PROJECT_ID’. * }).catch(function(error) { * // Handle error. * }); * ``` */ tenantId: string | null; /** * Returns a JSON-serializable representation of this object. * * @return A JSON-serializable representation of this object. */ toJSON(): Object; /** * Unlinks a provider from a user account. * * <h4>Error Codes</h4> * <dl> * <dt>auth/no-such-provider</dt> * <dd>Thrown if the user does not have this provider linked or when the * provider ID given does not exist.</dd> * </dt> * * @param providerId */ unlink(providerId: string): Promise<firebase.User>; /** * Updates the user's email address. * * An email will be sent to the original email address (if it was set) that * allows to revoke the email address change, in order to protect them from * account hijacking. * * <b>Important:</b> this is a security sensitive operation that requires the * user to have recently signed in. If this requirement isn't met, ask the user * to authenticate again and then call * {@link firebase.User.reauthenticateWithCredential}. * * <h4>Error Codes</h4> * <dl> * <dt>auth/invalid-email</dt> * <dd>Thrown if the email used is invalid.</dd> * <dt>auth/email-already-in-use</dt> * <dd>Thrown if the email is already used by another user.</dd> * <dt>auth/requires-recent-login</dt> * <dd>Thrown if the user's last sign-in time does not meet the security * threshold. Use {@link firebase.User.reauthenticateWithCredential} to * resolve. This does not apply if the user is anonymous.</dd> * </dl> * * @param newEmail The new email address. */ updateEmail(newEmail: string): Promise<void>; /** * Updates the user's password. * * <b>Important:</b> this is a security sensitive operation that requires the * user to have recently signed in. If this requirement isn't met, ask the user * to authenticate again and then call * {@link firebase.User.reauthenticateWithCredential}. * * <h4>Error Codes</h4> * <dl> * <dt>auth/weak-password</dt> * <dd>Thrown if the password is not strong enough.</dd> * <dt>auth/requires-recent-login</dt> * <dd>Thrown if the user's last sign-in time does not meet the security * threshold. Use {@link firebase.User.reauthenticateWithCredential} to * resolve. This does not apply if the user is anonymous.</dd> * </dl> * * @param newPassword */ updatePassword(newPassword: string): Promise<void>; /** * Updates the user's phone number. * * <h4>Error Codes</h4> * <dl> * <dt>auth/invalid-verification-code</dt> * <dd>Thrown if the verification code of the credential is not valid.</dd> * <dt>auth/invalid-verification-id</dt> * <dd>Thrown if the verification ID of the credential is not valid.</dd> * </dl> * * @param phoneCredential */ updatePhoneNumber( phoneCredential: firebase.auth.AuthCredential ): Promise<void>; /** * Updates a user's profile data. * * @example * ```javascript * // Updates the user attributes: * user.updateProfile({ * displayName: "Jane Q. User", * photoURL: "https://example.com/jane-q-user/profile.jpg" * }).then(function() { * // Profile updated successfully! * // "Jane Q. User" * var displayName = user.displayName; * // "https://example.com/jane-q-user/profile.jpg" * var photoURL = user.photoURL; * }, function(error) { * // An error happened. * }); * * // Passing a null value will delete the current attribute's value, but not * // passing a property won't change the current attribute's value: * // Let's say we're using the same user than before, after the update. * user.updateProfile({photoURL: null}).then(function() { * // Profile updated successfully! * // "Jane Q. User", hasn't changed. * var displayName = user.displayName; * // Now, this is null. * var photoURL = user.photoURL; * }, function(error) { * // An error happened. * }); * ``` * * @param profile The profile's * displayName and photoURL to update. */ updateProfile(profile: { displayName?: string | null; photoURL?: string | null; }): Promise<void>; /** * Sends a verification email to a new email address. The user's email will be * updated to the new one after being verified. * * If you have a custom email action handler, you can complete the verification * process by calling {@link firebase.auth.Auth.applyActionCode}. * * <h4>Error Codes</h4> * <dl> * <dt>auth/missing-android-pkg-name</dt> * <dd>An Android package name must be provided if the Android app is required * to be installed.</dd> * <dt>auth/missing-continue-uri</dt> * <dd>A continue URL must be provided in the request.</dd> * <dt>auth/missing-ios-bundle-id</dt> * <dd>An iOS bundle ID must be provided if an App Store ID is provided.</dd> * <dt>auth/invalid-continue-uri</dt> * <dd>The continue URL provided in the request is invalid.</dd> * <dt>auth/unauthorized-continue-uri</dt> * <dd>The domain of the continue URL is not whitelisted. Whitelist * the domain in the Firebase console.</dd> * </dl> * * @example * ```javascript * var actionCodeSettings = { * url: 'https://www.example.com/cart?email=user@example.com&cartId=123', * iOS: { * bundleId: 'com.example.ios' * }, * android: { * packageName: 'com.example.android', * installApp: true, * minimumVersion: '12' * }, * handleCodeInApp: true * }; * firebase.auth().currentUser.verifyBeforeUpdateEmail( * 'user@example.com', actionCodeSettings) * .then(function() { * // Verification email sent. * }) * .catch(function(error) { * // Error occurred. Inspect error.code. * }); * ``` * * @param newEmail The email address to be verified and updated to. * @param actionCodeSettings The action * code settings. If specified, the state/continue URL will be set as the * "continueUrl" parameter in the email verification link. The default email * verification landing page will use this to display a link to go back to * the app if it is installed. * If the actionCodeSettings is not specified, no URL is appended to the * action URL. * The state URL provided must belong to a domain that is whitelisted by the * developer in the console. Otherwise an error will be thrown. * Mobile app redirects will only be applicable if the developer configures * and accepts the Firebase Dynamic Links terms of condition. * The Android package name and iOS bundle ID will be respected only if they * are configured in the same Firebase Auth project used. */ verifyBeforeUpdateEmail( newEmail: string, actionCodeSettings?: firebase.auth.ActionCodeSettings | null ): Promise<void>; } /** * User profile information, visible only to the Firebase project's * apps. * */ interface UserInfo { displayName: string | null; email: string | null; phoneNumber: string | null; photoURL: string | null; providerId: string; /** * The user's unique ID. */ uid: string; } type FirebaseSignInProvider = | 'custom' | 'email' | 'password' | 'phone' | 'anonymous' | 'google.com' | 'facebook.com' | 'github.com' | 'twitter.com' | 'microsoft.com' | 'apple.com'; interface FirebaseIdToken { /** Always set to https://securetoken.google.com/PROJECT_ID */ iss: string; /** Always set to PROJECT_ID */ aud: string; /** The user's unique ID */ sub: string; /** The token issue time, in seconds since epoch */ iat: number; /** The token expiry time, normally 'iat' + 3600 */ exp: number; /** The user's unique ID. Must be equal to 'sub' */ user_id: string; /** The time the user authenticated, normally 'iat' */ auth_time: number; /** The sign in provider, only set when the provider is 'anonymous' */ provider_id?: 'anonymous'; /** The user's primary email */ email?: string; /** The user's email verification status */ email_verified?: boolean; /** The user's primary phone number */ phone_number?: string; /** The user's display name */ name?: string; /** The user's profile photo URL */ picture?: string; /** Information on all identities linked to this user */ firebase: { /** The primary sign-in provider */ sign_in_provider: FirebaseSignInProvider; /** A map of providers to the user's list of unique identifiers from each provider */ identities?: { [provider in FirebaseSignInProvider]?: string[] }; }; /** Custom claims set by the developer */ [claim: string]: unknown; // NO LONGER SUPPORTED. Use "sub" instead. (Not a jsdoc comment to avoid generating docs.) uid?: never; } export type EmulatorMockTokenOptions = ( | { user_id: string } | { sub: string } ) & Partial<FirebaseIdToken>; /** * Retrieves a Firebase {@link firebase.app.App app} instance. * * When called with no arguments, the default app is returned. When an app name * is provided, the app corresponding to that name is returned. * * An exception is thrown if the app being retrieved has not yet been * initialized. * * @example * ```javascript * // Return the default app * var app = firebase.app(); * ``` * * @example * ```javascript * // Return a named app * var otherApp = firebase.app("otherApp"); * ``` * * @param name Optional name of the app to return. If no name is * provided, the default is `"[DEFAULT]"`. * * @return The app corresponding to the provided app name. * If no app name is provided, the default app is returned. */ function app(name?: string): firebase.app.App; /** * A (read-only) array of all initialized apps. */ var apps: firebase.app.App[]; /** * Gets the {@link firebase.auth.Auth `Auth`} service for the default app or a * given app. * * `firebase.auth()` can be called with no arguments to access the default app's * {@link firebase.auth.Auth `Auth`} service or as `firebase.auth(app)` to * access the {@link firebase.auth.Auth `Auth`} service associated with a * specific app. * * @example * ```javascript * * // Get the Auth service for the default app * var defaultAuth = firebase.auth(); * ``` * @example * ```javascript * * // Get the Auth service for a given app * var otherAuth = firebase.auth(otherApp); * ``` * @param app */ function auth(app?: firebase.app.App): firebase.auth.Auth; /** * Gets the {@link firebase.database.Database `Database`} service for the * default app or a given app. * * `firebase.database()` can be called with no arguments to access the default * app's {@link firebase.database.Database `Database`} service or as * `firebase.database(app)` to access the * {@link firebase.database.Database `Database`} service associated with a * specific app. * * `firebase.database` is also a namespace that can be used to access global * constants and methods associated with the `Database` service. * * @example * ```javascript * // Get the Database service for the default app * var defaultDatabase = firebase.database(); * ``` * * @example * ```javascript * // Get the Database service for a specific app * var otherDatabase = firebase.database(app); * ``` * * @namespace * @param app Optional app whose Database service to * return. If not provided, the default Database service will be returned. * @return The default Database service if no app * is provided or the Database service associated with the provided app. */ function database(app?: firebase.app.App): firebase.database.Database; /** * Creates and initializes a Firebase {@link firebase.app.App app} instance. * * See * {@link * https://firebase.google.com/docs/web/setup#add_firebase_to_your_app * Add Firebase to your app} and * {@link * https://firebase.google.com/docs/web/learn-more#multiple-projects * Initialize multiple projects} for detailed documentation. * * @example * ```javascript * * // Initialize default app * // Retrieve your own options values by adding a web app on * // https://console.firebase.google.com * firebase.initializeApp({ * apiKey: "AIza....", // Auth / General Use * appId: "1:27992087142:web:ce....", // General Use * projectId: "my-firebase-project", // General Use * authDomain: "YOUR_APP.firebaseapp.com", // Auth with popup/redirect * databaseURL: "https://YOUR_APP.firebaseio.com", // Realtime Database * storageBucket: "YOUR_APP.appspot.com", // Storage * messagingSenderId: "123456789", // Cloud Messaging * measurementId: "G-12345" // Analytics * }); * ``` * * @example * ```javascript * * // Initialize another app * var otherApp = firebase.initializeApp({ * apiKey: "AIza....", * appId: "1:27992087142:web:ce....", * projectId: "my-firebase-project", * databaseURL: "https://<OTHER_DATABASE_NAME>.firebaseio.com", * storageBucket: "<OTHER_STORAGE_BUCKET>.appspot.com" * }, "nameOfOtherApp"); * ``` * * @param options Options to configure the app's services. * @param name Optional name of the app to initialize. If no name * is provided, the default is `"[DEFAULT]"`. * * @return {!firebase.app.App} The initialized app. */ function initializeApp(options: Object, name?: string): firebase.app.App; /** * Gets the