diff --git a/packages/auth/__tests__/auth.test.ts b/packages/auth/__tests__/auth.test.ts index 0c37fa1cd0..278281968e 100644 --- a/packages/auth/__tests__/auth.test.ts +++ b/packages/auth/__tests__/auth.test.ts @@ -1,6 +1,62 @@ import { describe, expect, it } from '@jest/globals'; -import auth, { firebase } from '../lib'; +import auth, { + firebase, + getAuth, + initializeAuth, + applyActionCode, + beforeAuthStateChanged, + checkActionCode, + confirmPasswordReset, + connectAuthEmulator, + createUserWithEmailAndPassword, + fetchSignInMethodsForEmail, + getMultiFactorResolver, + getRedirectResult, + isSignInWithEmailLink, + onAuthStateChanged, + onIdTokenChanged, + sendPasswordResetEmail, + sendSignInLinkToEmail, + setPersistence, + signInAnonymously, + signInWithCredential, + signInWithCustomToken, + signInWithEmailAndPassword, + signInWithEmailLink, + signInWithPhoneNumber, + verifyPhoneNumber, + signInWithPopup, + signInWithRedirect, + signOut, + updateCurrentUser, + useDeviceLanguage, + useUserAccessGroup, + verifyPasswordResetCode, + parseActionCodeURL, + deleteUser, + getIdToken, + getIdTokenResult, + linkWithCredential, + linkWithPhoneNumber, + linkWithPopup, + linkWithRedirect, + multiFactor, + reauthenticateWithCredential, + reauthenticateWithPhoneNumber, + reauthenticateWithPopup, + reauthenticateWithRedirect, + reload, + sendEmailVerification, + unlink, + updateEmail, + updatePassword, + updatePhoneNumber, + updateProfile, + verifyBeforeUpdateEmail, + getAdditionalUserInfo, + getCustomAuthDomain, +} from '../lib'; // @ts-ignore - We don't mind missing types here import { NativeFirebaseError } from '../../app/lib/internal'; @@ -118,4 +174,222 @@ describe('Auth', function () { expect(actual._auth).not.toBeNull(); }); }); + + describe('modular', function () { + it('`getAuth` function is properly exposed to end user', function () { + expect(getAuth).toBeDefined(); + }); + + it('`initializeAuth` function is properly exposed to end user', function () { + expect(initializeAuth).toBeDefined(); + }); + + it('`applyActionCode` function is properly exposed to end user', function () { + expect(applyActionCode).toBeDefined(); + }); + + it('`beforeAuthStateChanged` function is properly exposed to end user', function () { + expect(beforeAuthStateChanged).toBeDefined(); + }); + + it('`checkActionCode` function is properly exposed to end user', function () { + expect(checkActionCode).toBeDefined(); + }); + + it('`confirmPasswordReset` function is properly exposed to end user', function () { + expect(confirmPasswordReset).toBeDefined(); + }); + + it('`connectAuthEmulator` function is properly exposed to end user', function () { + expect(connectAuthEmulator).toBeDefined(); + }); + + it('`createUserWithEmailAndPassword` function is properly exposed to end user', function () { + expect(createUserWithEmailAndPassword).toBeDefined(); + }); + + it('`fetchSignInMethodsForEmail` function is properly exposed to end user', function () { + expect(fetchSignInMethodsForEmail).toBeDefined(); + }); + + it('`getMultiFactorResolver` function is properly exposed to end user', function () { + expect(getMultiFactorResolver).toBeDefined(); + }); + + it('`getRedirectResult` function is properly exposed to end user', function () { + expect(getRedirectResult).toBeDefined(); + }); + + it('`isSignInWithEmailLink` function is properly exposed to end user', function () { + expect(isSignInWithEmailLink).toBeDefined(); + }); + + it('`onAuthStateChanged` function is properly exposed to end user', function () { + expect(onAuthStateChanged).toBeDefined(); + }); + + it('`onIdTokenChanged` function is properly exposed to end user', function () { + expect(onIdTokenChanged).toBeDefined(); + }); + + it('`sendPasswordResetEmail` function is properly exposed to end user', function () { + expect(sendPasswordResetEmail).toBeDefined(); + }); + + it('`sendSignInLinkToEmail` function is properly exposed to end user', function () { + expect(sendSignInLinkToEmail).toBeDefined(); + }); + + it('`setPersistence` function is properly exposed to end user', function () { + expect(setPersistence).toBeDefined(); + }); + + it('`signInAnonymously` function is properly exposed to end user', function () { + expect(signInAnonymously).toBeDefined(); + }); + + it('`signInWithCredential` function is properly exposed to end user', function () { + expect(signInWithCredential).toBeDefined(); + }); + + it('`signInWithCustomToken` function is properly exposed to end user', function () { + expect(signInWithCustomToken).toBeDefined(); + }); + + it('`signInWithEmailAndPassword` function is properly exposed to end user', function () { + expect(signInWithEmailAndPassword).toBeDefined(); + }); + + it('`signInWithEmailLink` function is properly exposed to end user', function () { + expect(signInWithEmailLink).toBeDefined(); + }); + + it('`signInWithPhoneNumber` function is properly exposed to end user', function () { + expect(signInWithPhoneNumber).toBeDefined(); + }); + + it('`verifyPhoneNumber` function is properly exposed to end user', function () { + expect(verifyPhoneNumber).toBeDefined(); + }); + + it('`signInWithPopup` function is properly exposed to end user', function () { + expect(signInWithPopup).toBeDefined(); + }); + + it('`signInWithRedirect` function is properly exposed to end user', function () { + expect(signInWithRedirect).toBeDefined(); + }); + + it('`signOut` function is properly exposed to end user', function () { + expect(signOut).toBeDefined(); + }); + + it('`updateCurrentUser` function is properly exposed to end user', function () { + expect(updateCurrentUser).toBeDefined(); + }); + + it('`useDeviceLanguage` function is properly exposed to end user', function () { + expect(useDeviceLanguage).toBeDefined(); + }); + + it('`useUserAccessGroup` function is properly exposed to end user', function () { + expect(useUserAccessGroup).toBeDefined(); + }); + + it('`verifyPasswordResetCode` function is properly exposed to end user', function () { + expect(verifyPasswordResetCode).toBeDefined(); + }); + + it('`parseActionCodeURL` function is properly exposed to end user', function () { + expect(parseActionCodeURL).toBeDefined(); + }); + + it('`deleteUser` function is properly exposed to end user', function () { + expect(deleteUser).toBeDefined(); + }); + + it('`getIdToken` function is properly exposed to end user', function () { + expect(getIdToken).toBeDefined(); + }); + + it('`getIdTokenResult` function is properly exposed to end user', function () { + expect(getIdTokenResult).toBeDefined(); + }); + + it('`linkWithCredential` function is properly exposed to end user', function () { + expect(linkWithCredential).toBeDefined(); + }); + + it('`linkWithPhoneNumber` function is properly exposed to end user', function () { + expect(linkWithPhoneNumber).toBeDefined(); + }); + + it('`linkWithPopup` function is properly exposed to end user', function () { + expect(linkWithPopup).toBeDefined(); + }); + + it('`linkWithRedirect` function is properly exposed to end user', function () { + expect(linkWithRedirect).toBeDefined(); + }); + + it('`multiFactor` function is properly exposed to end user', function () { + expect(multiFactor).toBeDefined(); + }); + + it('`reauthenticateWithCredential` function is properly exposed to end user', function () { + expect(reauthenticateWithCredential).toBeDefined(); + }); + + it('`reauthenticateWithPhoneNumber` function is properly exposed to end user', function () { + expect(reauthenticateWithPhoneNumber).toBeDefined(); + }); + + it('`reauthenticateWithPopup` function is properly exposed to end user', function () { + expect(reauthenticateWithPopup).toBeDefined(); + }); + + it('`reauthenticateWithRedirect` function is properly exposed to end user', function () { + expect(reauthenticateWithRedirect).toBeDefined(); + }); + + it('`reload` function is properly exposed to end user', function () { + expect(reload).toBeDefined(); + }); + + it('`sendEmailVerification` function is properly exposed to end user', function () { + expect(sendEmailVerification).toBeDefined(); + }); + + it('`unlink` function is properly exposed to end user', function () { + expect(unlink).toBeDefined(); + }); + + it('`updateEmail` function is properly exposed to end user', function () { + expect(updateEmail).toBeDefined(); + }); + + it('`updatePassword` function is properly exposed to end user', function () { + expect(updatePassword).toBeDefined(); + }); + + it('`updatePhoneNumber` function is properly exposed to end user', function () { + expect(updatePhoneNumber).toBeDefined(); + }); + + it('`updateProfile` function is properly exposed to end user', function () { + expect(updateProfile).toBeDefined(); + }); + + it('`verifyBeforeUpdateEmail` function is properly exposed to end user', function () { + expect(verifyBeforeUpdateEmail).toBeDefined(); + }); + + it('`getAdditionalUserInfo` function is properly exposed to end user', function () { + expect(getAdditionalUserInfo).toBeDefined(); + }); + + it('`getCustomAuthDomain` function is properly exposed to end user', function () { + expect(getCustomAuthDomain).toBeDefined(); + }); + }); }); diff --git a/packages/auth/lib/index.d.ts b/packages/auth/lib/index.d.ts index 1f1bf07119..3ba68f2e91 100644 --- a/packages/auth/lib/index.d.ts +++ b/packages/auth/lib/index.d.ts @@ -2156,10 +2156,24 @@ export namespace FirebaseAuthTypes { * @param user The user. */ multiFactor(user: User): MultiFactorUser; + /** + * Returns the custom auth domain for the auth instance. + */ + getCustomAuthDomain(): Promise; + /** + * Sets the language code on the auth instance. This is to match Firebase JS SDK behavior. + * Please use the `setLanguageCode` method for setting the language code. + */ + set languageCode(code: string | null); + /** + * Gets the config used to initialize this auth instance. This is to match Firebase JS SDK behavior. + * It returns an empty map as the config is not available in the native SDK. + */ + get config(): Map; } } -type CallbackOrObserver any> = T | { next: T }; +export type CallbackOrObserver any> = T | { next: T }; declare const defaultExport: ReactNativeFirebase.FirebaseModuleWithStaticsAndApp< FirebaseAuthTypes.Module, @@ -2188,3 +2202,5 @@ declare module '@react-native-firebase/app' { } } } + +export * from './modular'; diff --git a/packages/auth/lib/index.js b/packages/auth/lib/index.js index 6f0f7a2f21..0cc488d6c8 100644 --- a/packages/auth/lib/index.js +++ b/packages/auth/lib/index.js @@ -47,63 +47,6 @@ import TwitterAuthProvider from './providers/TwitterAuthProvider'; import version from './version'; import fallBackModule from './web/RNFBAuthModule'; -export { - applyActionCode, - beforeAuthStateChanged, - checkActionCode, - confirmPasswordReset, - connectAuthEmulator, - createUserWithEmailAndPassword, - deleteUser, - fetchSignInMethodsForEmail, - getAdditionalUserInfo, - getAuth, - getCustomAuthDomain, - getIdToken, - getIdTokenResult, - getMultiFactorResolver, - getRedirectResult, - initializeAuth, - isSignInWithEmailLink, - linkWithCredential, - linkWithPhoneNumber, - linkWithPopup, - linkWithRedirect, - multiFactor, - onAuthStateChanged, - onIdTokenChanged, - parseActionCodeURL, - reauthenticateWithCredential, - reauthenticateWithPhoneNumber, - reauthenticateWithPopup, - reauthenticateWithRedirect, - reload, - sendEmailVerification, - sendPasswordResetEmail, - sendSignInLinkToEmail, - setPersistence, - signInAnonymously, - signInWithCredential, - signInWithCustomToken, - signInWithEmailAndPassword, - signInWithEmailLink, - signInWithPhoneNumber, - signInWithPopup, - signInWithRedirect, - signOut, - unlink, - updateCurrentUser, - updateEmail, - updatePassword, - updatePhoneNumber, - updateProfile, - useDeviceLanguage, - useUserAccessGroup, - verifyBeforeUpdateEmail, - verifyPasswordResetCode, - verifyPhoneNumber, -} from './modular/index'; -// For modular imports export { AppleAuthProvider, EmailAuthProvider, @@ -187,6 +130,32 @@ class FirebaseAuthModule extends FirebaseModule { return this._languageCode; } + set languageCode(code) { + // For modular API, not recommended to set languageCode directly as it should be set in the native SDKs first + if (!isString(code) && !isNull(code)) { + throw new Error( + "firebase.auth().languageCode = (*) expected 'languageCode' to be a string or null value", + ); + } + // as this is a setter, we can't use async/await. So we set it first so it is available immediately + if (code === null) { + this._languageCode = this.native.APP_LANGUAGE[this.app._name]; + + if (!this.languageCode) { + this._languageCode = this.native.APP_LANGUAGE['[DEFAULT]']; + } + } else { + this._languageCode = code; + } + // This sets it natively + this.setLanguageCode(code); + } + + get config() { + // for modular API, firebase JS SDK has a config object which is not available in native SDKs + return {}; + } + get tenantId() { return this._tenantId; } @@ -530,6 +499,8 @@ export default createModuleNamespace({ ModuleClass: FirebaseAuthModule, }); +export * from './modular/index'; + // import auth, { firebase } from '@react-native-firebase/auth'; // auth().X(...); // firebase.auth().X(...); diff --git a/packages/auth/lib/modular/index.d.ts b/packages/auth/lib/modular/index.d.ts new file mode 100644 index 0000000000..b8f99d8dd0 --- /dev/null +++ b/packages/auth/lib/modular/index.d.ts @@ -0,0 +1,662 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* + * Copyright (c) 2016-present Invertase Limited & Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this library 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. + */ + +import { FirebaseApp } from '@firebase/app-types'; +import { FirebaseAuthTypes, CallbackOrObserver, AuthListenerCallback } from '../index'; +import { firebase } from '..'; + +import Auth = FirebaseAuthTypes.Module; + +/** + * Returns the Auth instance associated with the provided FirebaseApp. + * @param app - The Firebase app instance. + * @returns The Auth instance. + */ +export function getAuth(app?: FirebaseApp): Auth; + +/** + * This function allows more control over the Auth instance than getAuth(). + * + * @param app - The Firebase app instance. + * @param deps - Optional. Dependencies for the Auth instance. + * @returns The Auth instance. + * + * getAuth uses platform-specific defaults to supply the Dependencies. + * In general, getAuth is the easiest way to initialize Auth and works for most use cases. + * Use initializeAuth if you need control over which persistence layer is used, or to minimize bundle size + * if you're not using either signInWithPopup or signInWithRedirect. + */ +export function initializeAuth(app: FirebaseApp, deps?: any): Auth; + +/** + * Applies a verification code sent to the user by email or other out-of-band mechanism. + * + * @param auth - The Auth instance. + * @param oobCode - The out-of-band code sent to the user. + * @returns A promise that resolves when the code is applied successfully. + */ +export function applyActionCode(auth: Auth, oobCode: string): Promise; + +/** + * Adds a blocking callback that runs before an auth state change sets a new user. + * + * @param auth - The Auth instance. + * @param callback - A callback function to run before the auth state changes. + * @param onAbort - Optional. A callback function to run if the operation is aborted. + */ +export function beforeAuthStateChanged( + auth: Auth, + callback: (user: FirebaseAuthTypes.User | null) => void, + onAbort?: () => void, +): void; + +/** + * Checks a verification code sent to the user by email or other out-of-band mechanism. + * + * @param auth - The Auth instance. + * @param oobCode - The out-of-band code sent to the user. + * @returns A promise that resolves with the action code information. + */ +export function checkActionCode( + auth: Auth, + oobCode: string, +): Promise; + +/** + * Completes the password reset process, given a confirmation code and new password. + * + * @param auth - The Auth instance. + * @param oobCode - The out-of-band code sent to the user. + * @param newPassword - The new password. + * @returns A promise that resolves when the password is reset. + */ +export function confirmPasswordReset( + auth: Auth, + oobCode: string, + newPassword: string, +): Promise; + +/** + * Changes the Auth instance to communicate with the Firebase Auth Emulator, instead of production Firebase Auth services. + * + * @param auth - The Auth instance. + * @param url - The URL of the Firebase Auth Emulator. + * @param options - Optional. Options for the emulator connection. + * + * This must be called synchronously immediately following the first call to initializeAuth(). Do not use with production credentials as emulator traffic is not encrypted. + */ +export function connectAuthEmulator( + auth: Auth, + url: string, + options?: { disableWarnings: boolean }, +): void; + +/** + * Creates a new user account associated with the specified email address and password. + * + * @param auth - The Auth instance. + * @param email - The user's email address. + * @param password - The user's password. + * @returns A promise that resolves with the user credentials. + */ +export function createUserWithEmailAndPassword( + auth: Auth, + email: string, + password: string, +): Promise; + +/** + * Gets the list of possible sign in methods for the given email address. + * + * @param auth - The Auth instance. + * @param email - The user's email address. + * @returns A promise that resolves with the list of sign-in methods. + */ +export function fetchSignInMethodsForEmail(auth: Auth, email: string): Promise; + +/** + * Provides a MultiFactorResolver suitable for completion of a multi-factor flow. + * + * @param auth - The Auth instance. + * @param error - The multi-factor error. + * @returns The MultiFactorResolver instance. + */ +export function getMultiFactorResolver( + auth: Auth, + error: FirebaseAuthTypes.MultiFactorError, +): FirebaseAuthTypes.MultiFactorResolver; + +/** + * Returns a UserCredential from the redirect-based sign-in flow. + * + * @param auth - The Auth instance. + * @param resolver - Optional. The popup redirect resolver. + * @returns A promise that resolves with the user credentials or null. + */ +export interface PopupRedirectResolver {} + +export function getRedirectResult( + auth: Auth, + resolver?: PopupRedirectResolver, +): Promise; + +/** + * Checks if an incoming link is a sign-in with email link suitable for signInWithEmailLink(). + * + * @param auth - The Auth instance. + * @param emailLink - The email link to check. + * @returns True if the link is a sign-in with email link. + */ +export function isSignInWithEmailLink(auth: Auth, emailLink: string): boolean; + +/** + * Adds an observer for changes to the user's sign-in state. + * + * @param auth - The Auth instance. + * @param nextOrObserver - A callback function or observer for auth state changes. + * @returns A function to unsubscribe from the auth state changes. + */ +export function onAuthStateChanged( + auth: Auth, + nextOrObserver: CallbackOrObserver, +): () => void; + +/** + * Adds an observer for changes to the signed-in user's ID token. + * + * @param auth - The Auth instance. + * @param nextOrObserver - A callback function or observer for ID token changes. + * @returns A function to unsubscribe from the ID token changes. + */ +export function onIdTokenChanged( + auth: Auth, + nextOrObserver: CallbackOrObserver, +): () => void; + +/** + * Sends a password reset email to the given email address. + * + * @param auth - The Auth instance. + * @param email - The user's email address. + * @param actionCodeSettings - Optional. Action code settings. + * @returns A promise that resolves when the email is sent. + */ +export function sendPasswordResetEmail( + auth: Auth, + email: string, + actionCodeSettings?: FirebaseAuthTypes.ActionCodeSettings, +): Promise; + +/** + * Sends a sign-in email link to the user with the specified email. + * + * @param auth - The Auth instance. + * @param email - The user's email address. + * @param actionCodeSettings - Optional. Action code settings. + * @returns A promise that resolves when the email is sent. + */ +export function sendSignInLinkToEmail( + auth: Auth, + email: string, + actionCodeSettings?: FirebaseAuthTypes.ActionCodeSettings, +): Promise; + +/** + * Type of Persistence. + * - 'SESSION' is used for temporary persistence such as `sessionStorage`. + * - 'LOCAL' is used for long term persistence such as `localStorage` or `IndexedDB`. + * - 'NONE' is used for in-memory, or no persistence. + */ +export type Persistence = { + readonly type: 'SESSION' | 'LOCAL' | 'NONE'; +}; + +/** + * Changes the type of persistence on the Auth instance for the currently saved Auth session and applies this type of persistence for future sign-in requests, including sign-in with redirect requests. + * + * @param auth - The Auth instance. + * @param persistence - The persistence type. + * @returns A promise that resolves when the persistence is set. + */ +export function setPersistence(auth: Auth, persistence: Persistence): Promise; + +/** + * Asynchronously signs in as an anonymous user. + * + * @param auth - The Auth instance. + * @returns A promise that resolves with the user credentials. + */ +export function signInAnonymously(auth: Auth): Promise; + +/** + * Asynchronously signs in with the given credentials. + * + * @param auth - The Auth instance. + * @param credential - The auth credentials. + * @returns A promise that resolves with the user credentials. + */ +export function signInWithCredential( + auth: Auth, + credential: FirebaseAuthTypes.AuthCredential, +): Promise; + +/** + * Asynchronously signs in using a custom token. + * + * @param auth - The Auth instance. + * @param customToken - The custom token. + * @returns A promise that resolves with the user credentials. + */ +export function signInWithCustomToken( + auth: Auth, + customToken: string, +): Promise; + +/** + * Asynchronously signs in using an email and password. + * + * @param auth - The Auth instance. + * @param email - The user's email address. + * @param password - The user's password. + * @returns A promise that resolves with the user credentials. + */ +export function signInWithEmailAndPassword( + auth: Auth, + email: string, + password: string, +): Promise; + +/** + * Asynchronously signs in using an email and sign-in email link. + * + * @param auth - The Auth instance. + * @param email - The user's email address. + * @param emailLink - The email link. + * @returns A promise that resolves with the user credentials. + */ +export function signInWithEmailLink( + auth: Auth, + email: string, + emailLink: string, +): Promise; + +/** + * Interface representing an application verifier. + */ +export interface ApplicationVerifier { + type: string; + verify(): Promise; +} + +/** + * Asynchronously signs in using a phone number. + * + * @param auth - The Auth instance. + * @param phoneNumber - The user's phone number. + * @param appVerifier - The application verifier. + * @returns A promise that resolves with the confirmation result. + */ +export function signInWithPhoneNumber( + auth: Auth, + phoneNumber: string, + appVerifier: ApplicationVerifier, +): Promise; + +/** + * Asynchronously signs in using a phone number. + * + * @param auth - The Auth instance. + * @param phoneNumber - The user's phone number. + * @param autoVerifyTimeoutOrForceResend - The auto verify timeout or force resend flag. + * @param forceResend - Optional. Whether to force resend. + * @returns A promise that resolves with the phone auth listener. + */ +export function verifyPhoneNumber( + auth: Auth, + phoneNumber: string, + autoVerifyTimeoutOrForceResend: number | boolean, + forceResend?: boolean, +): FirebaseAuthTypes.PhoneAuthListener; + +/** + * Authenticates a Firebase client using a popup-based OAuth authentication flow. + * + * @param auth - The Auth instance. + * @param provider - The auth provider. + * @param resolver - Optional. The popup redirect resolver. + * @returns A promise that resolves with the user credentials. + */ +export function signInWithPopup( + auth: Auth, + provider: FirebaseAuthTypes.AuthProvider, + resolver?: PopupRedirectResolver, +): Promise; + +/** + * Authenticates a Firebase client using a full-page redirect flow. + * + * @param auth - The Auth instance. + * @param provider - The auth provider. + * @param resolver - Optional. The popup redirect resolver. + * @returns A promise that resolves when the redirect is complete. + */ +export function signInWithRedirect( + auth: Auth, + provider: FirebaseAuthTypes.AuthProvider, + resolver?: PopupRedirectResolver, +): Promise; + +/** + * Signs out the current user. + * + * @param auth - The Auth instance. + * @returns A promise that resolves when the user is signed out. + */ +export function signOut(auth: Auth): Promise; + +/** + * Asynchronously sets the provided user as Auth.currentUser on the Auth instance. + * + * @param auth - The Auth instance. + * @param user - The user to set as the current user. + * @returns A promise that resolves when the user is set. + */ +export function updateCurrentUser(auth: Auth, user: FirebaseAuthTypes.User): Promise; + +/** + * Sets the current language to the default device/browser preference. + * + * @param auth - The Auth instance. + */ +export function useDeviceLanguage(auth: Auth): void; + +/** + * Sets the current language to the default device/browser preference. + * + * @param auth - The Auth instance. + * @param userAccessGroup - The user access group. + * @returns A promise that resolves when the user access group is set. + */ +export function useUserAccessGroup(auth: Auth, userAccessGroup: string): Promise; + +/** + * Verifies the password reset code sent to the user by email or other out-of-band mechanism. + * + * @param auth - The Auth instance. + * @param code - The password reset code. + * @returns A promise that resolves with the user's email address. + */ +export function verifyPasswordResetCode(auth: Auth, code: string): Promise; + +/** + * Parses the email action link string and returns an ActionCodeURL if the link is valid, otherwise returns null. + * + * @param link - The email action link string. + * @returns The ActionCodeURL if the link is valid, otherwise null. + */ +export function parseActionCodeURL(link: string): FirebaseAuthTypes.ActionCodeURL | null; + +/** + * Deletes and signs out the user. + * + * @param user - The user to delete. + * @returns A promise that resolves when the user is deleted. + */ +export function deleteUser(user: FirebaseAuthTypes.User): Promise; + +/** + * Returns a JSON Web Token (JWT) used to identify the user to a Firebase service. + * + * @param user - The user to get the token for. + * @param forceRefresh - Optional. Whether to force refresh the token. + * @returns A promise that resolves with the token. + */ +export function getIdToken(user: FirebaseAuthTypes.User, forceRefresh?: boolean): Promise; + +/** + * Returns a deserialized JSON Web Token (JWT) used to identify the user to a Firebase service. + * + * @param user - The user to get the token result for. + * @param forceRefresh - Optional. Whether to force refresh the token. + * @returns A promise that resolves with the token result. + */ +export function getIdTokenResult( + user: FirebaseAuthTypes.User, + forceRefresh?: boolean, +): Promise; + +/** + * Links the user account with the given credentials. + * + * @param user - The user to link the credentials with. + * @param credential - The auth credentials. + * @returns A promise that resolves with the user credentials. + */ +export function linkWithCredential( + user: FirebaseAuthTypes.User, + credential: FirebaseAuthTypes.AuthCredential, +): Promise; + +/** + * Links the user account with the given phone number. + * + * @param user - The user to link the phone number with. + * @param phoneNumber - The phone number. + * @param appVerifier - The application verifier. + * @returns A promise that resolves with the confirmation result. + */ +export function linkWithPhoneNumber( + user: FirebaseAuthTypes.User, + phoneNumber: string, + appVerifier: ApplicationVerifier, +): Promise; + +/** + * Links the authenticated provider to the user account using a pop-up based OAuth flow. + * + * @param user - The user to link the provider with. + * @param provider - The auth provider. + * @param resolver - Optional. The popup redirect resolver. + * @returns A promise that resolves with the user credentials. + */ +export function linkWithPopup( + user: FirebaseAuthTypes.User, + provider: FirebaseAuthTypes.AuthProvider, + resolver?: PopupRedirectResolver, +): Promise; + +/** + * Links the OAuthProvider to the user account using a full-page redirect flow. + * + * @param user - The user to link the provider with. + * @param provider - The auth provider. + * @param resolver - Optional. The popup redirect resolver. + * @returns A promise that resolves when the redirect is complete. + */ +export function linkWithRedirect( + user: FirebaseAuthTypes.User, + provider: FirebaseAuthTypes.AuthProvider, + resolver?: PopupRedirectResolver, +): Promise; + +/** + * The MultiFactorUser corresponding to the user. + * + * @param user - The user to get the multi-factor user for. + * @returns The MultiFactorUser instance. + */ +export function multiFactor(user: FirebaseAuthTypes.User): FirebaseAuthTypes.MultiFactorUser; + +/** + * Re-authenticates a user using a fresh credential. + * + * @param user - The user to re-authenticate. + * @param credential - The auth credentials. + * @returns A promise that resolves with the user credentials. + */ +export function reauthenticateWithCredential( + user: FirebaseAuthTypes.User, + credential: FirebaseAuthTypes.AuthCredential, +): Promise; + +/** + * Re-authenticates a user using a fresh phone credential. + * + * @param user - The user to re-authenticate. + * @param phoneNumber - The phone number. + * @param appVerifier - The application verifier. + * @returns A promise that resolves with the confirmation result. + */ +export function reauthenticateWithPhoneNumber( + user: FirebaseAuthTypes.User, + phoneNumber: string, + appVerifier: ApplicationVerifier, +): Promise; + +/** + * Reauthenticates the current user with the specified OAuthProvider using a pop-up based OAuth flow. + * + * @param user - The user to re-authenticate. + * @param provider - The auth provider. + * @param resolver - Optional. The popup redirect resolver. + * @returns A promise that resolves with the user credentials. + */ +export function reauthenticateWithPopup( + user: FirebaseAuthTypes.User, + provider: FirebaseAuthTypes.AuthProvider, + resolver?: PopupRedirectResolver, +): Promise; + +/** + * Reauthenticates the current user with the specified OAuthProvider using a full-page redirect flow. + * + * @param user - The user to re-authenticate. + * @param provider - The auth provider. + * @param resolver - Optional. The popup redirect resolver. + * @returns A promise that resolves when the redirect is complete. + */ +export function reauthenticateWithRedirect( + user: FirebaseAuthTypes.User, + provider: FirebaseAuthTypes.AuthProvider, + resolver?: PopupRedirectResolver, +): Promise; + +/** + * Reloads user account data, if signed in. + * + * @param user - The user to reload data for. + * @returns A promise that resolves when the data is reloaded. + */ +export function reload(user: FirebaseAuthTypes.User): Promise; + +/** + * Sends a verification email to a user. + * + * @param user - The user to send the email to. + * @param actionCodeSettings - Optional. Action code settings. + * @returns A promise that resolves when the email is sent. + */ +export function sendEmailVerification( + user: FirebaseAuthTypes.User, + actionCodeSettings?: FirebaseAuthTypes.ActionCodeSettings, +): Promise; + +/** + * Unlinks a provider from a user account. + * + * @param user - The user to unlink the provider from. + * @param providerId - The provider ID. + * @returns A promise that resolves with the user. + */ +export function unlink( + user: FirebaseAuthTypes.User, + providerId: string, +): Promise; + +/** + * Updates the user's email address. + * + * @param user - The user to update the email for. + * @param newEmail - The new email address. + * @returns A promise that resolves when the email is updated. + */ +export function updateEmail(user: FirebaseAuthTypes.User, newEmail: string): Promise; + +/** + * Updates the user's password. + * + * @param user - The user to update the password for. + * @param newPassword - The new password. + * @returns A promise that resolves when the password is updated. + */ +export function updatePassword(user: FirebaseAuthTypes.User, newPassword: string): Promise; + +/** + * Updates the user's phone number. + * + * @param user - The user to update the phone number for. + * @param credential - The auth credentials. + * @returns A promise that resolves when the phone number is updated. + */ +export function updatePhoneNumber( + user: FirebaseAuthTypes.User, + credential: FirebaseAuthTypes.AuthCredential, +): Promise; + +/** + * Updates a user's profile data. + * + * @param user - The user to update the profile for. + * @param profile - An object containing the profile data to update. + * @returns A promise that resolves when the profile is updated. + */ +export function updateProfile( + user: FirebaseAuthTypes.User, + { displayName, photoURL: photoUrl }: { displayName?: string | null; photoURL?: string | null }, +): Promise; + +/** + * Sends a verification email to a new email address. + * + * @param user - The user to send the email to. + * @param newEmail - The new email address. + * @param actionCodeSettings - Optional. Action code settings. + * @returns A promise that resolves when the email is sent. + */ +export function verifyBeforeUpdateEmail( + user: FirebaseAuthTypes.User, + newEmail: string, + actionCodeSettings?: FirebaseAuthTypes.ActionCodeSettings, +): Promise; + +/** + * Extracts provider specific AdditionalUserInfo for the given credential. + * + * @param userCredential - The user credential. + * @returns The additional user information, or null if none is available. + */ +export function getAdditionalUserInfo( + userCredential: FirebaseAuthTypes.UserCredential, +): FirebaseAuthTypes.AdditionalUserInfo | null; + +/** + * Returns the custom auth domain for the auth instance. + * + * @param auth - The Auth instance. + * @returns A promise that resolves with the custom auth domain. + */ +export function getCustomAuthDomain(auth: Auth): Promise; diff --git a/packages/auth/lib/modular/index.js b/packages/auth/lib/modular/index.js index a9b43bfec4..7afb43cef7 100644 --- a/packages/auth/lib/modular/index.js +++ b/packages/auth/lib/modular/index.js @@ -13,462 +13,582 @@ * 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. - * */ -import { isString } from '@react-native-firebase/app/lib/common'; import { firebase } from '..'; -/* +/** + * @typedef {import('@firebase/app-types').FirebaseApp} FirebaseApp + * @typedef {import('..').FirebaseAuthTypes} FirebaseAuthTypes + * @typedef {import('..').FirebaseAuthTypes.Module} Auth + * @typedef {import('..').FirebaseAuthTypes.CallbackOrObserver} CallbackOrObserver + * @typedef {import('..').FirebaseAuthTypes.AuthListenerCallback} AuthListenerCallback + * @typedef {import('..').FirebaseAuthTypes.ActionCodeInfo} ActionCodeInfo + * @typedef {import('..').FirebaseAuthTypes.UserCredential} UserCredential + * @typedef {import('..').FirebaseAuthTypes.MultiFactorError} MultiFactorError + * @typedef {import('..').FirebaseAuthTypes.MultiFactorUser} MultiFactorUser + * @typedef {import('..').FirebaseAuthTypes.MultiFactorResolver} MultiFactorResolver + * @typedef {import('..').FirebaseAuthTypes.ConfirmationResult} ConfirmationResult + * @typedef {import('..').FirebaseAuthTypes.AuthCredential} AuthCredential + * @typedef {import('..').FirebaseAuthTypes.AuthProvider} AuthProvider + * @typedef {import('..').FirebaseAuthTypes.PhoneAuthListener} PhoneAuthListener + * @typedef {import('..').FirebaseAuthTypes.ActionCodeSettings} ActionCodeSettings + * @typedef {import('..').FirebaseAuthTypes.User} User + * @typedef {import('..').FirebaseAuthTypes.IdTokenResult} IdTokenResult + * @typedef {import('..').FirebaseAuthTypes.AdditionalUserInfo} AdditionalUserInfo + * @typedef {import('..').FirebaseAuthTypes.ActionCodeURL} ActionCodeURL + * @typedef {import('..').FirebaseAuthTypes.ApplicationVerifier} ApplicationVerifier + */ + +/** * Returns the Auth instance associated with the provided FirebaseApp. - */ -class Auth { - constructor(app) { - this.app = app ? firebase.app(app.name) : firebase.app(); - this._languageCode = this.app.auth().languageCode; - } - - get config() { - return this.app.auth().config; - } - - get currentUser() { - return this.app.auth().currentUser; - } - - get languageCode() { - return this._languageCode; - } - - set languageCode(code) { - if (code === null || isString(code)) { - this._languageCode = code; - this.app.auth().languageCode = code; - return; - } - throw new Error("expected 'languageCode' to be a string or null value"); - } - - get settings() { - return this.app.auth().settings; - } - - get tenantId() { - return this.app.auth().tenantId; - } -} - -/* - * Returns the Auth instance associated with the provided FirebaseApp. - * - * If no instance exists, initializes an Auth instance with platform-specific default dependencies. + * @param {FirebaseApp} [app] - The Firebase app instance. + * @returns {Auth} */ export function getAuth(app) { - return new Auth(app); -} - -function _getUnderlyingAuth(auth) { - return auth.app.auth(); + if (app) { + return firebase.app(app.name).auth(); + } + return firebase.app().auth(); } -/* +/** * This function allows more control over the Auth instance than getAuth(). - * - * getAuth uses platform-specific defaults to supply the Dependencies. - * In general, getAuth is the easiest way to initialize Auth and works for most use cases. - * Use initializeAuth if you need control over which persistence layer is used, or to minimize bundle size - * if you're not using either signInWithPopup or signInWithRedirect. + * @param {FirebaseApp} app - The Firebase app instance. + * @param {any} [deps] - Optional. Dependencies for the Auth instance. + * @returns {Auth} */ export function initializeAuth(app, deps) { - return getAuth(app); + if (app) { + return firebase.app(app.name).auth(); + } + return firebase.app().auth(); } -/* +/** * Applies a verification code sent to the user by email or other out-of-band mechanism. - * - * Returns a promise that resolves when the code is applied successfully. + * @param {Auth} auth - The Auth instance. + * @param {string} oobCode - The out-of-band code sent to the user. + * @returns {Promise} */ export async function applyActionCode(auth, oobCode) { - const _auth = _getUnderlyingAuth(auth); - return _auth.applyActionCode(oobCode); + return auth.applyActionCode(oobCode); } -/* +/** * Adds a blocking callback that runs before an auth state change sets a new user. + * @param {Auth} auth - The Auth instance. + * @param {(user: User | null) => void} callback - A callback function to run before the auth state changes. + * @param {() => void} [onAbort] - Optional. A callback function to run if the operation is aborted. */ export function beforeAuthStateChanged(auth, callback, onAbort) { throw new Error('beforeAuthStateChanged is unsupported by the native Firebase SDKs'); } -/* +/** * Checks a verification code sent to the user by email or other out-of-band mechanism. + * @param {Auth} auth - The Auth instance. + * @param {string} oobCode - The out-of-band code sent to the user. + * @returns {Promise} */ export async function checkActionCode(auth, oobCode) { - const _auth = _getUnderlyingAuth(auth); - return _auth.checkActionCode(oobCode); + return auth.checkActionCode(oobCode); } -/* +/** * Completes the password reset process, given a confirmation code and new password. + * @param {Auth} auth - The Auth instance. + * @param {string} oobCode - The out-of-band code sent to the user. + * @param {string} newPassword - The new password. + * @returns {Promise} */ export async function confirmPasswordReset(auth, oobCode, newPassword) { - const _auth = _getUnderlyingAuth(auth); - return _auth.confirmPasswordReset(oobCode, newPassword); + return auth.confirmPasswordReset(oobCode, newPassword); } -/* +/** * Changes the Auth instance to communicate with the Firebase Auth Emulator, instead of production Firebase Auth services. - * - * This must be called synchronously immediately following the first call to initializeAuth(). Do not use with production credentials as emulator traffic is not encrypted. + * @param {Auth} auth - The Auth instance. + * @param {string} url - The URL of the Firebase Auth Emulator. + * @param {{ disableWarnings: boolean }} [options] - Optional. Options for the emulator connection. */ export function connectAuthEmulator(auth, url, options) { - const _auth = _getUnderlyingAuth(auth); - _auth.useEmulator(url, options); + auth.useEmulator(url, options); } -/* +/** * Creates a new user account associated with the specified email address and password. + * @param {Auth} auth - The Auth instance. + * @param {string} email - The user's email address. + * @param {string} password - The user's password. + * @returns {Promise} */ export async function createUserWithEmailAndPassword(auth, email, password) { - const _auth = _getUnderlyingAuth(auth); - return _auth.createUserWithEmailAndPassword(email, password); + return auth.createUserWithEmailAndPassword(email, password); } -/* +/** * Gets the list of possible sign in methods for the given email address. + * @param {Auth} auth - The Auth instance. + * @param {string} email - The user's email address. + * @returns {Promise} */ export async function fetchSignInMethodsForEmail(auth, email) { - const _auth = _getUnderlyingAuth(auth); - return _auth.fetchSignInMethodsForEmail(email); + return auth.fetchSignInMethodsForEmail(email); } -/* +/** * Provides a MultiFactorResolver suitable for completion of a multi-factor flow. + * @param {Auth} auth - The Auth instance. + * @param {MultiFactorError} error - The multi-factor error. + * @returns {MultiFactorResolver} */ export function getMultiFactorResolver(auth, error) { - const _auth = _getUnderlyingAuth(auth); - return _auth.getMultiFactorResolver(error); + return auth.getMultiFactorResolver(error); } -/* +/** * Returns a UserCredential from the redirect-based sign-in flow. + * @param {Auth} auth - The Auth instance. + * @param {PopupRedirectResolver} [resolver] - Optional. The popup redirect resolver. + * @returns {Promise} */ export async function getRedirectResult(auth, resolver) { throw new Error('getRedirectResult is unsupported by the native Firebase SDKs'); } -/* +/** * Checks if an incoming link is a sign-in with email link suitable for signInWithEmailLink(). + * @param {Auth} auth - The Auth instance. + * @param {string} emailLink - The email link to check. + * @returns {boolean} */ export function isSignInWithEmailLink(auth, emailLink) { - const _auth = _getUnderlyingAuth(auth); - return _auth.isSignInWithEmailLink(emailLink); + return auth.isSignInWithEmailLink(emailLink); } -/* +/** * Adds an observer for changes to the user's sign-in state. + * @param {Auth} auth - The Auth instance. + * @param {CallbackOrObserver} nextOrObserver - A callback function or observer for auth state changes. + * @returns {() => void} */ export function onAuthStateChanged(auth, nextOrObserver) { - const _auth = _getUnderlyingAuth(auth); - return _auth.onAuthStateChanged(nextOrObserver); + return auth.onAuthStateChanged(nextOrObserver); } -/* +/** * Adds an observer for changes to the signed-in user's ID token. + * @param {Auth} auth - The Auth instance. + * @param {CallbackOrObserver} nextOrObserver - A callback function or observer for ID token changes. + * @returns {() => void} */ export function onIdTokenChanged(auth, nextOrObserver) { - const _auth = _getUnderlyingAuth(auth); - return _auth.onIdTokenChanged(nextOrObserver); + return auth.onIdTokenChanged(nextOrObserver); } -/* +/** * Sends a password reset email to the given email address. + * @param {Auth} auth - The Auth instance. + * @param {string} email - The user's email address. + * @param {ActionCodeSettings} [actionCodeSettings] - Optional. Action code settings. + * @returns {Promise} */ export async function sendPasswordResetEmail(auth, email, actionCodeSettings) { - const _auth = _getUnderlyingAuth(auth); - return _auth.sendPasswordResetEmail(email, actionCodeSettings); + return auth.sendPasswordResetEmail(email, actionCodeSettings); } -/* +/** * Sends a sign-in email link to the user with the specified email. + * @param {Auth} auth - The Auth instance. + * @param {string} email - The user's email address. + * @param {ActionCodeSettings} [actionCodeSettings] - Optional. Action code settings. + * @returns {Promise} */ export async function sendSignInLinkToEmail(auth, email, actionCodeSettings) { - const _auth = _getUnderlyingAuth(auth); - return _auth.sendSignInLinkToEmail(email, actionCodeSettings); + return auth.sendSignInLinkToEmail(email, actionCodeSettings); } -/* +/** * Changes the type of persistence on the Auth instance for the currently saved Auth session and applies this type of persistence for future sign-in requests, including sign-in with redirect requests. + * @param {Auth} auth - The Auth instance. + * @param {Persistence} persistence - The persistence type. + * @returns {Promise} */ export async function setPersistence(auth, persistence) { throw new Error('setPersistence is unsupported by the native Firebase SDKs'); } -/* +/** * Asynchronously signs in as an anonymous user. + * @param {Auth} auth - The Auth instance. + * @returns {Promise} */ export async function signInAnonymously(auth) { - const _auth = _getUnderlyingAuth(auth); - return _auth.signInAnonymously(); + return auth.signInAnonymously(); } -/* +/** * Asynchronously signs in with the given credentials. + * @param {Auth} auth - The Auth instance. + * @param {AuthCredential} credential - The auth credentials. + * @returns {Promise} */ export async function signInWithCredential(auth, credential) { - const _auth = _getUnderlyingAuth(auth); - return _auth.signInWithCredential(credential); + return auth.signInWithCredential(credential); } -/* +/** * Asynchronously signs in using a custom token. + * @param {Auth} auth - The Auth instance. + * @param {string} customToken - The custom token. + * @returns {Promise} */ export async function signInWithCustomToken(auth, customToken) { - const _auth = _getUnderlyingAuth(auth); - return _auth.signInWithCustomToken(customToken); + return auth.signInWithCustomToken(customToken); } -/* +/** * Asynchronously signs in using an email and password. + * @param {Auth} auth - The Auth instance. + * @param {string} email - The user's email address. + * @param {string} password - The user's password. + * @returns {Promise} */ export async function signInWithEmailAndPassword(auth, email, password) { - const _auth = _getUnderlyingAuth(auth); - return _auth.signInWithEmailAndPassword(email, password); + return auth.signInWithEmailAndPassword(email, password); } -/* +/** * Asynchronously signs in using an email and sign-in email link. + * @param {Auth} auth - The Auth instance. + * @param {string} email - The user's email address. + * @param {string} emailLink - The email link. + * @returns {Promise} */ export async function signInWithEmailLink(auth, email, emailLink) { - const _auth = _getUnderlyingAuth(auth); - return _auth.signInWithEmailLink(email, emailLink); + return auth.signInWithEmailLink(email, emailLink); } -/* +/** * Asynchronously signs in using a phone number. + * @param {Auth} auth - The Auth instance. + * @param {string} phoneNumber - The user's phone number. + * @param {ApplicationVerifier} appVerifier - The application verifier. + * @returns {Promise} */ export async function signInWithPhoneNumber(auth, phoneNumber, appVerifier) { - const _auth = _getUnderlyingAuth(auth); - return _auth.signInWithPhoneNumber(phoneNumber); + return auth.signInWithPhoneNumber(phoneNumber, appVerifier); } -/* - * Asynchronously signs in using a phone number. +/** + * Asynchronously verifies a phone number. + * @param {Auth} auth - The Auth instance. + * @param {string} phoneNumber - The user's phone number. + * @param {number | boolean} autoVerifyTimeoutOrForceResend - The auto verify timeout or force resend flag. + * @param {boolean} [forceResend] - Optional. Whether to force resend. + * @returns {PhoneAuthListener} */ export function verifyPhoneNumber(auth, phoneNumber, autoVerifyTimeoutOrForceResend, forceResend) { - const _auth = _getUnderlyingAuth(auth); - return _auth.verifyPhoneNumber(phoneNumber, autoVerifyTimeoutOrForceResend, forceResend); + return auth.verifyPhoneNumber(phoneNumber, autoVerifyTimeoutOrForceResend, forceResend); } -/* -Authenticates a Firebase client using a popup-based OAuth authentication flow. -*/ +/** + * Authenticates a Firebase client using a popup-based OAuth authentication flow. + * @param {Auth} auth - The Auth instance. + * @param {AuthProvider} provider - The auth provider. + * @param {PopupRedirectResolver} [resolver] - Optional. The popup redirect resolver. + * @returns {Promise} + */ export async function signInWithPopup(auth, provider, resolver) { - const _auth = _getUnderlyingAuth(auth); - return _auth.signInWithPopup(provider, resolver); + return auth.signInWithPopup(provider, resolver); } -/* -Authenticates a Firebase client using a full-page redirect flow. -*/ +/** + * Authenticates a Firebase client using a full-page redirect flow. + * @param {Auth} auth - The Auth instance. + * @param {AuthProvider} provider - The auth provider. + * @param {PopupRedirectResolver} [resolver] - Optional. The popup redirect resolver. + * @returns {Promise} + */ export async function signInWithRedirect(auth, provider, resolver) { - const _auth = _getUnderlyingAuth(auth); - return _auth.signInWithRedirect(provider, resolver); + return auth.signInWithRedirect(provider, resolver); } -/* -Signs out the current user. -*/ +/** + * Signs out the current user. + * @param {Auth} auth - The Auth instance. + * @returns {Promise} + */ export async function signOut(auth) { - const _auth = _getUnderlyingAuth(auth); - return _auth.signOut(); + return auth.signOut(); } -/* -Asynchronously sets the provided user as Auth.currentUser on the Auth instance. -*/ +/** + * Asynchronously sets the provided user as Auth.currentUser on the Auth instance. + * @param {Auth} auth - The Auth instance. + * @param {User} user - The user to set as the current user. + * @returns {Promise} + */ export async function updateCurrentUser(auth, user) { throw new Error('updateCurrentUser is unsupported by the native Firebase SDKs'); } -/* -Sets the current language to the default device/browser preference. -*/ +/** + * Sets the current language to the default device/browser preference. + * @param {Auth} auth - The Auth instance. + */ export function useDeviceLanguage(auth) { throw new Error('useDeviceLanguage is unsupported by the native Firebase SDKs'); } -/* - Sets the current language to the default device/browser preference. -*/ +/** + * Sets the current language to the default device/browser preference. + * @param {Auth} auth - The Auth instance. + * @param {string} userAccessGroup - The user access group. + * @returns {Promise} + */ export function useUserAccessGroup(auth, userAccessGroup) { - const _auth = _getUnderlyingAuth(auth); - return _auth.useUserAccessGroup(userAccessGroup); + return auth.useUserAccessGroup(userAccessGroup); } -/* -Verifies the password reset code sent to the user by email or other out-of-band mechanism. -*/ +/** + * Verifies the password reset code sent to the user by email or other out-of-band mechanism. + * @param {Auth} auth - The Auth instance. + * @param {string} code - The password reset code. + * @returns {Promise} + */ export async function verifyPasswordResetCode(auth, code) { - const _auth = _getUnderlyingAuth(auth); - return _auth.verifyPasswordResetCode(code); + return auth.verifyPasswordResetCode(code); } -/* +/** * Parses the email action link string and returns an ActionCodeURL if the link is valid, otherwise returns null. + * @param {string} link - The email action link string. + * @returns {ActionCodeURL | null} */ export function parseActionCodeURL(link) { throw new Error('parseActionCodeURL is unsupported by the native Firebase SDKs'); } -/* +/** * Deletes and signs out the user. + * @param {User} user - The user to delete. + * @returns {Promise} */ export async function deleteUser(user) { return user.delete(); } -/* +/** * Returns a JSON Web Token (JWT) used to identify the user to a Firebase service. + * @param {User} user - The user to get the token for. + * @param {boolean} [forceRefresh] - Optional. Whether to force refresh the token. + * @returns {Promise} */ export async function getIdToken(user, forceRefresh) { return user.getIdToken(forceRefresh); } -/* +/** * Returns a deserialized JSON Web Token (JWT) used to identify the user to a Firebase service. + * @param {User} user - The user to get the token result for. + * @param {boolean} [forceRefresh] - Optional. Whether to force refresh the token. + * @returns {Promise} */ export async function getIdTokenResult(user, forceRefresh) { return user.getIdTokenResult(forceRefresh); } -/* +/** * Links the user account with the given credentials. + * @param {User} user - The user to link the credentials with. + * @param {AuthCredential} credential - The auth credentials. + * @returns {Promise} */ export async function linkWithCredential(user, credential) { return user.linkWithCredential(credential); } -/* +/** * Links the user account with the given phone number. + * @param {User} user - The user to link the phone number with. + * @param {string} phoneNumber - The phone number. + * @param {ApplicationVerifier} appVerifier - The application verifier. + * @returns {Promise} */ export async function linkWithPhoneNumber(user, phoneNumber, appVerifier) { throw new Error('linkWithPhoneNumber is unsupported by the native Firebase SDKs'); } -/* +/** * Links the authenticated provider to the user account using a pop-up based OAuth flow. + * @param {User} user - The user to link the provider with. + * @param {AuthProvider} provider - The auth provider. + * @param {PopupRedirectResolver} [resolver] - Optional. The popup redirect resolver. + * @returns {Promise} */ export async function linkWithPopup(user, provider, resolver) { return user.linkWithPopup(provider, resolver); } -/* +/** * Links the OAuthProvider to the user account using a full-page redirect flow. + * @param {User} user - The user to link the provider with. + * @param {AuthProvider} provider - The auth provider. + * @param {PopupRedirectResolver} [resolver] - Optional. The popup redirect resolver. + * @returns {Promise} */ export async function linkWithRedirect(user, provider, resolver) { return user.linkWithRedirect(provider, resolver); } -/* +/** * The MultiFactorUser corresponding to the user. + * @param {User} user - The user to get the multi-factor user for. + * @returns {MultiFactorUser} */ export function multiFactor(user) { return user._auth.multiFactor(user); } -/* +/** * Re-authenticates a user using a fresh credential. + * @param {User} user - The user to re-authenticate. + * @param {AuthCredential} credential - The auth credentials. + * @returns {Promise} */ export async function reauthenticateWithCredential(user, credential) { return user.reauthenticateWithCredential(credential); } -/* +/** * Re-authenticates a user using a fresh phone credential. + * @param {User} user - The user to re-authenticate. + * @param {string} phoneNumber - The phone number. + * @param {ApplicationVerifier} appVerifier - The application verifier. + * @returns {Promise} */ export async function reauthenticateWithPhoneNumber(user, phoneNumber, appVerifier) { throw new Error('reauthenticateWithPhoneNumber is unsupported by the native Firebase SDKs'); } -/* +/** * Reauthenticates the current user with the specified OAuthProvider using a pop-up based OAuth flow. + * @param {User} user - The user to re-authenticate. + * @param {AuthProvider} provider - The auth provider. + * @param {PopupRedirectResolver} [resolver] - Optional. The popup redirect resolver. + * @returns {Promise} */ export async function reauthenticateWithPopup(user, provider, resolver) { return user.reauthenticateWithPopup(provider, resolver); } -/* +/** * Reauthenticates the current user with the specified OAuthProvider using a full-page redirect flow. + * @param {User} user - The user to re-authenticate. + * @param {AuthProvider} provider - The auth provider. + * @param {PopupRedirectResolver} [resolver] - Optional. The popup redirect resolver. + * @returns {Promise} */ export async function reauthenticateWithRedirect(user, provider, resolver) { return user.reauthenticateWithRedirect(provider, resolver); } -/* +/** * Reloads user account data, if signed in. + * @param {User} user - The user to reload data for. + * @returns {Promise} */ export async function reload(user) { return user.reload(); } -/* +/** * Sends a verification email to a user. + * @param {User} user - The user to send the email to. + * @param {ActionCodeSettings} [actionCodeSettings] - Optional. Action code settings. + * @returns {Promise} */ export async function sendEmailVerification(user, actionCodeSettings) { return user.sendEmailVerification(actionCodeSettings); } -/* +/** * Unlinks a provider from a user account. + * @param {User} user - The user to unlink the provider from. + * @param {string} providerId - The provider ID. + * @returns {Promise} */ export async function unlink(user, providerId) { return user.unlink(providerId); } -/* +/** * Updates the user's email address. + * @param {User} user - The user to update the email for. + * @param {string} newEmail - The new email address. + * @returns {Promise} */ export async function updateEmail(user, newEmail) { return user.updateEmail(newEmail); } -/* +/** * Updates the user's password. + * @param {User} user - The user to update the password for. + * @param {string} newPassword - The new password. + * @returns {Promise} */ export async function updatePassword(user, newPassword) { return user.updatePassword(newPassword); } -/* +/** * Updates the user's phone number. + * @param {User} user - The user to update the phone number for. + * @param {AuthCredential} credential - The auth credentials. + * @returns {Promise} */ export async function updatePhoneNumber(user, credential) { return user.updatePhoneNumber(credential); } -/* +/** * Updates a user's profile data. + * @param {User} user - The user to update the profile for. + * @param {{ displayName?: string | null, photoURL?: string | null }} profile - An object containing the profile data to update. + * @returns {Promise} */ export async function updateProfile(user, { displayName, photoURL: photoUrl }) { return user.updateProfile({ displayName, photoURL: photoUrl }); } -/* +/** * Sends a verification email to a new email address. + * @param {User} user - The user to send the email to. + * @param {string} newEmail - The new email address. + * @param {ActionCodeSettings} [actionCodeSettings] - Optional. Action code settings. + * @returns {Promise} */ export async function verifyBeforeUpdateEmail(user, newEmail, actionCodeSettings) { return user.verifyBeforeUpdateEmail(newEmail, actionCodeSettings); } -/* +/** * Extracts provider specific AdditionalUserInfo for the given credential. + * @param {UserCredential} userCredential - The user credential. + * @returns {AdditionalUserInfo | null} */ export function getAdditionalUserInfo(userCredential) { return userCredential.additionalUserInfo; } +/** + * Returns the custom auth domain for the auth instance. + * @param {Auth} auth - The Auth instance. + * @returns {Promise} + */ export function getCustomAuthDomain(auth) { - const _auth = _getUnderlyingAuth(auth); - return _auth.getCustomAuthDomain(); + return auth.getCustomAuthDomain(); }