diff --git a/common/api-review/auth-exp.api.md b/common/api-review/auth-exp.api.md index 0ecb7952829..a009e94a326 100644 --- a/common/api-review/auth-exp.api.md +++ b/common/api-review/auth-exp.api.md @@ -20,18 +20,18 @@ export interface ActionCodeInfo { multiFactorInfo?: MultiFactorInfo | null; previousEmail?: string | null; }; - operation: ActionCodeOperation; + operation: typeof ActionCodeOperation[keyof typeof ActionCodeOperation]; } // @public -export const enum ActionCodeOperation { - EMAIL_SIGNIN = "EMAIL_SIGNIN", - PASSWORD_RESET = "PASSWORD_RESET", - RECOVER_EMAIL = "RECOVER_EMAIL", - REVERT_SECOND_FACTOR_ADDITION = "REVERT_SECOND_FACTOR_ADDITION", - VERIFY_AND_CHANGE_EMAIL = "VERIFY_AND_CHANGE_EMAIL", - VERIFY_EMAIL = "VERIFY_EMAIL" -} +export const ActionCodeOperation: { + readonly EMAIL_SIGNIN: "EMAIL_SIGNIN"; + readonly PASSWORD_RESET: "PASSWORD_RESET"; + readonly RECOVER_EMAIL: "RECOVER_EMAIL"; + readonly REVERT_SECOND_FACTOR_ADDITION: "REVERT_SECOND_FACTOR_ADDITION"; + readonly VERIFY_AND_CHANGE_EMAIL: "VERIFY_AND_CHANGE_EMAIL"; + readonly VERIFY_EMAIL: "VERIFY_EMAIL"; +}; // @public export interface ActionCodeSettings { @@ -56,7 +56,7 @@ export class ActionCodeURL { readonly code: string; readonly continueUrl: string | null; readonly languageCode: string | null; - readonly operation: ActionCodeOperation; + readonly operation: string; static parseLink(link: string): ActionCodeURL | null; readonly tenantId: string | null; } @@ -239,9 +239,9 @@ export class FacebookAuthProvider extends BaseOAuthProvider { } // @public -export const enum FactorId { - PHONE = "phone" -} +export const FactorId: { + readonly PHONE: "phone"; +}; // @public export function fetchSignInMethodsForEmail(auth: Auth, email: string): Promise; @@ -324,19 +324,19 @@ export function multiFactor(user: User): MultiFactorUser; // @public export interface MultiFactorAssertion { - readonly factorId: FactorId; + readonly factorId: typeof FactorId[keyof typeof FactorId]; } // @public export interface MultiFactorError extends AuthError { - readonly operationType: OperationType; + readonly operationType: typeof OperationType[keyof typeof OperationType]; } // @public export interface MultiFactorInfo { readonly displayName?: string | null; readonly enrollmentTime: string; - readonly factorId: FactorId; + readonly factorId: typeof FactorId[keyof typeof FactorId]; readonly uid: string; } @@ -405,11 +405,11 @@ export function onAuthStateChanged(auth: Auth, nextOrObserver: NextOrObserver, error?: ErrorFn, completed?: CompleteFn): Unsubscribe; // @public -export const enum OperationType { - LINK = "link", - REAUTHENTICATE = "reauthenticate", - SIGN_IN = "signIn" -} +export const OperationType: { + readonly LINK: "link"; + readonly REAUTHENTICATE: "reauthenticate"; + readonly SIGN_IN: "signIn"; +}; // @public export function parseActionCodeURL(link: string): ActionCodeURL | null; @@ -502,20 +502,14 @@ export interface PopupRedirectResolver { export const prodErrorMap: AuthErrorMap; // @public -export const enum ProviderId { - // @internal (undocumented) - ANONYMOUS = "anonymous", - // @internal (undocumented) - CUSTOM = "custom", - FACEBOOK = "facebook.com", - // @internal (undocumented) - FIREBASE = "firebase", - GITHUB = "github.com", - GOOGLE = "google.com", - PASSWORD = "password", - PHONE = "phone", - TWITTER = "twitter.com" -} +export const ProviderId: { + readonly FACEBOOK: "facebook.com"; + readonly GITHUB: "github.com"; + readonly GOOGLE: "google.com"; + readonly PASSWORD: "password"; + readonly PHONE: "phone"; + readonly TWITTER: "twitter.com"; +}; // @public export interface ReactNativeAsyncStorage { @@ -583,17 +577,15 @@ export function setPersistence(auth: Auth, persistence: Persistence): Promise; // @public -export const enum SignInMethod { - // @internal (undocumented) - ANONYMOUS = "anonymous", - EMAIL_LINK = "emailLink", - EMAIL_PASSWORD = "password", - FACEBOOK = "facebook.com", - GITHUB = "github.com", - GOOGLE = "google.com", - PHONE = "phone", - TWITTER = "twitter.com" -} +export const SignInMethod: { + readonly EMAIL_LINK: "emailLink"; + readonly EMAIL_PASSWORD: "password"; + readonly FACEBOOK: "facebook.com"; + readonly GITHUB: "github.com"; + readonly GOOGLE: "google.com"; + readonly PHONE: "phone"; + readonly TWITTER: "twitter.com"; +}; // @public export function signInWithCredential(auth: Auth, credential: AuthCredential): Promise; @@ -630,7 +622,7 @@ export class TwitterAuthProvider extends BaseOAuthProvider { } // @public -export function unlink(user: User, providerId: ProviderId): Promise; +export function unlink(user: User, providerId: string): Promise; export { Unsubscribe } @@ -677,7 +669,7 @@ export interface User extends UserInfo { // @public export interface UserCredential { - operationType: OperationType; + operationType: typeof OperationType[keyof typeof OperationType]; providerId: string | null; user: User; } diff --git a/packages-exp/auth-compat-exp/src/user.ts b/packages-exp/auth-compat-exp/src/user.ts index 62a00086ffa..8d47d726d56 100644 --- a/packages-exp/auth-compat-exp/src/user.ts +++ b/packages-exp/auth-compat-exp/src/user.ts @@ -158,7 +158,7 @@ export class User implements compat.User, Compat { return exp.sendEmailVerification(this._delegate, actionCodeSettings); } async unlink(providerId: string): Promise { - await exp.unlink(this._delegate, providerId as exp.ProviderId); + await exp.unlink(this._delegate, providerId); return this; } updateEmail(newEmail: string): Promise { diff --git a/packages-exp/auth-exp/index.node.ts b/packages-exp/auth-exp/index.node.ts index cb0a30cedb0..24c1562cf1e 100644 --- a/packages-exp/auth-exp/index.node.ts +++ b/packages-exp/auth-exp/index.node.ts @@ -41,6 +41,13 @@ FetchProvider.initialize( // Core functionality shared by all clients export * from './src'; +export { + FactorId, + ProviderId, + SignInMethod, + OperationType, + ActionCodeOperation +} from './src/model/enum_maps'; export function getAuth(app: FirebaseApp): Auth { const provider = _getProvider(app, 'auth-exp'); diff --git a/packages-exp/auth-exp/index.ts b/packages-exp/auth-exp/index.ts index 62f8204f643..b9d74996b7f 100644 --- a/packages-exp/auth-exp/index.ts +++ b/packages-exp/auth-exp/index.ts @@ -33,12 +33,6 @@ import { Auth } from './src/model/public_types'; // Public types export { - // Enums - ActionCodeOperation, - FactorId, - OperationType, - ProviderId, - SignInMethod, // Interfaces ActionCodeInfo, ActionCodeSettings, @@ -79,6 +73,15 @@ export { Unsubscribe } from './src/model/public_types'; +// Helper maps (not used internally) +export { + FactorId, + ProviderId, + SignInMethod, + OperationType, + ActionCodeOperation +} from './src/model/enum_maps'; + // Core functionality shared by all clients export * from './src'; diff --git a/packages-exp/auth-exp/src/core/action_code_url.ts b/packages-exp/auth-exp/src/core/action_code_url.ts index 6a40b43416c..123ad6f7dde 100644 --- a/packages-exp/auth-exp/src/core/action_code_url.ts +++ b/packages-exp/auth-exp/src/core/action_code_url.ts @@ -107,7 +107,7 @@ export class ActionCodeURL { * The action performed by the email action link. It returns from one of the types from * {@link ActionCodeInfo} */ - readonly operation: ActionCodeOperation; + readonly operation: string; /** * The tenant ID of the email action link. Null if the email action is from the parent project. */ diff --git a/packages-exp/auth-exp/src/core/user/link_unlink.ts b/packages-exp/auth-exp/src/core/user/link_unlink.ts index d71d28270ad..756aa654015 100644 --- a/packages-exp/auth-exp/src/core/user/link_unlink.ts +++ b/packages-exp/auth-exp/src/core/user/link_unlink.ts @@ -36,10 +36,7 @@ import { getModularInstance } from '@firebase/util'; * * @public */ -export async function unlink( - user: User, - providerId: ProviderId -): Promise { +export async function unlink(user: User, providerId: string): Promise { const userInternal = getModularInstance(user) as UserInternal; await _assertLinkedStatus(true, userInternal, providerId); const { providerUserInfo } = await deleteLinkedAccounts(userInternal.auth, { diff --git a/packages-exp/auth-exp/src/model/enum_maps.ts b/packages-exp/auth-exp/src/model/enum_maps.ts new file mode 100644 index 00000000000..4d3e3f4a59c --- /dev/null +++ b/packages-exp/auth-exp/src/model/enum_maps.ts @@ -0,0 +1,102 @@ +/** + * @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. + */ + +/** + * An enum of factors that may be used for multifactor authentication. + * + * @public + */ +export const FactorId = { + /** Phone as second factor */ + PHONE: 'phone' +} as const; + +/** + * Enumeration of supported providers. + * + * @public + */ +export const ProviderId = { + /** Facebook provider ID */ + FACEBOOK: 'facebook.com', + /** GitHub provider ID */ + GITHUB: 'github.com', + /** Google provider ID */ + GOOGLE: 'google.com', + /** Password provider */ + PASSWORD: 'password', + /** Phone provider */ + PHONE: 'phone', + /** Twitter provider ID */ + TWITTER: 'twitter.com' +} as const; + +/** + * Enumeration of supported sign-in methods. + * + * @public + */ +export const SignInMethod = { + /** Email link sign in method */ + EMAIL_LINK: 'emailLink', + /** Email/password sign in method */ + EMAIL_PASSWORD: 'password', + /** Facebook sign in method */ + FACEBOOK: 'facebook.com', + /** GitHub sign in method */ + GITHUB: 'github.com', + /** Google sign in method */ + GOOGLE: 'google.com', + /** Phone sign in method */ + PHONE: 'phone', + /** Twitter sign in method */ + TWITTER: 'twitter.com' +} as const; + +/** + * Enumeration of supported operation types. + * + * @public + */ +export const OperationType = { + /** Operation involving linking an additional provider to an already signed-in user. */ + LINK: 'link', + /** Operation involving using a provider to reauthenticate an already signed-in user. */ + REAUTHENTICATE: 'reauthenticate', + /** Operation involving signing in a user. */ + SIGN_IN: 'signIn' +} as const; + +/** + * An enumeration of the possible email action types. + * + * @public + */ +export const ActionCodeOperation = { + /** The email link sign-in action. */ + EMAIL_SIGNIN: 'EMAIL_SIGNIN', + /** The password reset action. */ + PASSWORD_RESET: 'PASSWORD_RESET', + /** The email revocation action. */ + RECOVER_EMAIL: 'RECOVER_EMAIL', + /** The revert second factor addition email action. */ + REVERT_SECOND_FACTOR_ADDITION: 'REVERT_SECOND_FACTOR_ADDITION', + /** The revert second factor addition email action. */ + VERIFY_AND_CHANGE_EMAIL: 'VERIFY_AND_CHANGE_EMAIL', + /** The email verification action. */ + VERIFY_EMAIL: 'VERIFY_EMAIL' +} as const; diff --git a/packages-exp/auth-exp/src/model/public_types.ts b/packages-exp/auth-exp/src/model/public_types.ts index ba55efd44ea..27a47be0c46 100644 --- a/packages-exp/auth-exp/src/model/public_types.ts +++ b/packages-exp/auth-exp/src/model/public_types.ts @@ -24,11 +24,17 @@ import { Unsubscribe } from '@firebase/util'; +import { + FactorId as FactorIdMap, + OperationType as OperationTypeMap, + ActionCodeOperation as ActionCodeOperationMap +} from './enum_maps'; + export { CompleteFn, ErrorFn, NextFn, Unsubscribe }; /** * Enumeration of supported providers. * - * @public + * @internal */ export const enum ProviderId { /** @internal */ @@ -54,7 +60,7 @@ export const enum ProviderId { /** * Enumeration of supported sign-in methods. * - * @public + * @internal */ export const enum SignInMethod { /** @internal */ @@ -78,7 +84,7 @@ export const enum SignInMethod { /** * Enumeration of supported operation types. * - * @public + * @internal */ export const enum OperationType { /** Operation involving linking an additional provider to an already signed-in user. */ @@ -431,13 +437,13 @@ export interface ActionCodeInfo { /** * The type of operation that generated the action code. */ - operation: ActionCodeOperation; + operation: typeof ActionCodeOperationMap[keyof typeof ActionCodeOperationMap]; } /** * An enumeration of the possible email action types. * - * @public + * @internal */ export const enum ActionCodeOperation { /** The email link sign-in action. */ @@ -556,7 +562,7 @@ export interface AuthProvider { /** * An enum of factors that may be used for multifactor authentication. * - * @public + * @internal */ export const enum FactorId { /** Phone as second factor */ @@ -603,7 +609,7 @@ export interface ConfirmationResult { */ export interface MultiFactorAssertion { /** The identifier of the second factor. */ - readonly factorId: FactorId; + readonly factorId: typeof FactorIdMap[keyof typeof FactorIdMap]; } /** @@ -641,7 +647,7 @@ export interface MultiFactorError extends AuthError { /** * The type of operation (e.g., sign-in, link, or reauthenticate) during which the error was raised. */ - readonly operationType: OperationType; + readonly operationType: typeof OperationTypeMap[keyof typeof OperationTypeMap]; } /** @@ -657,7 +663,7 @@ export interface MultiFactorInfo { /** The enrollment date of the second factor formatted as a UTC string. */ readonly enrollmentTime: string; /** The identifier of the second factor. */ - readonly factorId: FactorId; + readonly factorId: typeof FactorIdMap[keyof typeof FactorIdMap]; } /** @@ -1044,7 +1050,7 @@ export interface UserCredential { /** * The type of operation which was used to authenticate the user (such as sign-in or link). */ - operationType: OperationType; + operationType: typeof OperationTypeMap[keyof typeof OperationTypeMap]; } /**