Skip to content

Commit a075b5f

Browse files
sam-gcyuchenshi
andauthored
[Auth] Add exported const map for error codes (#5182)
* Add an exported error map const to Auth * Formatting * PR feedback * Update packages-exp/auth-exp/src/core/errors.ts Co-authored-by: Yuchen Shi <[email protected]>
1 parent a3cbe71 commit a075b5f

File tree

3 files changed

+213
-3
lines changed

3 files changed

+213
-3
lines changed

common/api-review/auth-exp.api.md

+99
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,105 @@ export interface AuthError extends FirebaseError {
126126
readonly tenantid?: string;
127127
}
128128

129+
// @public
130+
export const AuthErrorCodes: {
131+
readonly ADMIN_ONLY_OPERATION: "auth/admin-restricted-operation";
132+
readonly ARGUMENT_ERROR: "auth/argument-error";
133+
readonly APP_NOT_AUTHORIZED: "auth/app-not-authorized";
134+
readonly APP_NOT_INSTALLED: "auth/app-not-installed";
135+
readonly CAPTCHA_CHECK_FAILED: "auth/captcha-check-failed";
136+
readonly CODE_EXPIRED: "auth/code-expired";
137+
readonly CORDOVA_NOT_READY: "auth/cordova-not-ready";
138+
readonly CORS_UNSUPPORTED: "auth/cors-unsupported";
139+
readonly CREDENTIAL_ALREADY_IN_USE: "auth/credential-already-in-use";
140+
readonly CREDENTIAL_MISMATCH: "auth/custom-token-mismatch";
141+
readonly CREDENTIAL_TOO_OLD_LOGIN_AGAIN: "auth/requires-recent-login";
142+
readonly DEPENDENT_SDK_INIT_BEFORE_AUTH: "auth/dependent-sdk-initialized-before-auth";
143+
readonly DYNAMIC_LINK_NOT_ACTIVATED: "auth/dynamic-link-not-activated";
144+
readonly EMAIL_CHANGE_NEEDS_VERIFICATION: "auth/email-change-needs-verification";
145+
readonly EMAIL_EXISTS: "auth/email-already-in-use";
146+
readonly EMULATOR_CONFIG_FAILED: "auth/emulator-config-failed";
147+
readonly EXPIRED_OOB_CODE: "auth/expired-action-code";
148+
readonly EXPIRED_POPUP_REQUEST: "auth/cancelled-popup-request";
149+
readonly INTERNAL_ERROR: "auth/internal-error";
150+
readonly INVALID_API_KEY: "auth/invalid-api-key";
151+
readonly INVALID_APP_CREDENTIAL: "auth/invalid-app-credential";
152+
readonly INVALID_APP_ID: "auth/invalid-app-id";
153+
readonly INVALID_AUTH: "auth/invalid-user-token";
154+
readonly INVALID_AUTH_EVENT: "auth/invalid-auth-event";
155+
readonly INVALID_CERT_HASH: "auth/invalid-cert-hash";
156+
readonly INVALID_CODE: "auth/invalid-verification-code";
157+
readonly INVALID_CONTINUE_URI: "auth/invalid-continue-uri";
158+
readonly INVALID_CORDOVA_CONFIGURATION: "auth/invalid-cordova-configuration";
159+
readonly INVALID_CUSTOM_TOKEN: "auth/invalid-custom-token";
160+
readonly INVALID_DYNAMIC_LINK_DOMAIN: "auth/invalid-dynamic-link-domain";
161+
readonly INVALID_EMAIL: "auth/invalid-email";
162+
readonly INVALID_EMULATOR_SCHEME: "auth/invalid-emulator-scheme";
163+
readonly INVALID_IDP_RESPONSE: "auth/invalid-credential";
164+
readonly INVALID_MESSAGE_PAYLOAD: "auth/invalid-message-payload";
165+
readonly INVALID_MFA_SESSION: "auth/invalid-multi-factor-session";
166+
readonly INVALID_OAUTH_CLIENT_ID: "auth/invalid-oauth-client-id";
167+
readonly INVALID_OAUTH_PROVIDER: "auth/invalid-oauth-provider";
168+
readonly INVALID_OOB_CODE: "auth/invalid-action-code";
169+
readonly INVALID_ORIGIN: "auth/unauthorized-domain";
170+
readonly INVALID_PASSWORD: "auth/wrong-password";
171+
readonly INVALID_PERSISTENCE: "auth/invalid-persistence-type";
172+
readonly INVALID_PHONE_NUMBER: "auth/invalid-phone-number";
173+
readonly INVALID_PROVIDER_ID: "auth/invalid-provider-id";
174+
readonly INVALID_RECIPIENT_EMAIL: "auth/invalid-recipient-email";
175+
readonly INVALID_SENDER: "auth/invalid-sender";
176+
readonly INVALID_SESSION_INFO: "auth/invalid-verification-id";
177+
readonly INVALID_TENANT_ID: "auth/invalid-tenant-id";
178+
readonly MFA_INFO_NOT_FOUND: "auth/multi-factor-info-not-found";
179+
readonly MFA_REQUIRED: "auth/multi-factor-auth-required";
180+
readonly MISSING_ANDROID_PACKAGE_NAME: "auth/missing-android-pkg-name";
181+
readonly MISSING_APP_CREDENTIAL: "auth/missing-app-credential";
182+
readonly MISSING_AUTH_DOMAIN: "auth/auth-domain-config-required";
183+
readonly MISSING_CODE: "auth/missing-verification-code";
184+
readonly MISSING_CONTINUE_URI: "auth/missing-continue-uri";
185+
readonly MISSING_IFRAME_START: "auth/missing-iframe-start";
186+
readonly MISSING_IOS_BUNDLE_ID: "auth/missing-ios-bundle-id";
187+
readonly MISSING_OR_INVALID_NONCE: "auth/missing-or-invalid-nonce";
188+
readonly MISSING_MFA_INFO: "auth/missing-multi-factor-info";
189+
readonly MISSING_MFA_SESSION: "auth/missing-multi-factor-session";
190+
readonly MISSING_PHONE_NUMBER: "auth/missing-phone-number";
191+
readonly MISSING_SESSION_INFO: "auth/missing-verification-id";
192+
readonly MODULE_DESTROYED: "auth/app-deleted";
193+
readonly NEED_CONFIRMATION: "auth/account-exists-with-different-credential";
194+
readonly NETWORK_REQUEST_FAILED: "auth/network-request-failed";
195+
readonly NULL_USER: "auth/null-user";
196+
readonly NO_AUTH_EVENT: "auth/no-auth-event";
197+
readonly NO_SUCH_PROVIDER: "auth/no-such-provider";
198+
readonly OPERATION_NOT_ALLOWED: "auth/operation-not-allowed";
199+
readonly OPERATION_NOT_SUPPORTED: "auth/operation-not-supported-in-this-environment";
200+
readonly POPUP_BLOCKED: "auth/popup-blocked";
201+
readonly POPUP_CLOSED_BY_USER: "auth/popup-closed-by-user";
202+
readonly PROVIDER_ALREADY_LINKED: "auth/provider-already-linked";
203+
readonly QUOTA_EXCEEDED: "auth/quota-exceeded";
204+
readonly REDIRECT_CANCELLED_BY_USER: "auth/redirect-cancelled-by-user";
205+
readonly REDIRECT_OPERATION_PENDING: "auth/redirect-operation-pending";
206+
readonly REJECTED_CREDENTIAL: "auth/rejected-credential";
207+
readonly SECOND_FACTOR_ALREADY_ENROLLED: "auth/second-factor-already-in-use";
208+
readonly SECOND_FACTOR_LIMIT_EXCEEDED: "auth/maximum-second-factor-count-exceeded";
209+
readonly TENANT_ID_MISMATCH: "auth/tenant-id-mismatch";
210+
readonly TIMEOUT: "auth/timeout";
211+
readonly TOKEN_EXPIRED: "auth/user-token-expired";
212+
readonly TOO_MANY_ATTEMPTS_TRY_LATER: "auth/too-many-requests";
213+
readonly UNAUTHORIZED_DOMAIN: "auth/unauthorized-continue-uri";
214+
readonly UNSUPPORTED_FIRST_FACTOR: "auth/unsupported-first-factor";
215+
readonly UNSUPPORTED_PERSISTENCE: "auth/unsupported-persistence-type";
216+
readonly UNSUPPORTED_TENANT_OPERATION: "auth/unsupported-tenant-operation";
217+
readonly UNVERIFIED_EMAIL: "auth/unverified-email";
218+
readonly USER_CANCELLED: "auth/user-cancelled";
219+
readonly USER_DELETED: "auth/user-not-found";
220+
readonly USER_DISABLED: "auth/user-disabled";
221+
readonly USER_MISMATCH: "auth/user-mismatch";
222+
readonly USER_SIGNED_OUT: "auth/user-signed-out";
223+
readonly WEAK_PASSWORD: "auth/weak-password";
224+
readonly WEB_STORAGE_UNSUPPORTED: "auth/web-storage-unsupported";
225+
readonly ALREADY_INITIALIZED: "auth/already-initialized";
226+
};
227+
129228
// @public
130229
export interface AuthErrorMap {
131230
}

packages-exp/auth-exp/src/core/errors.ts

+109-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ import { AuthCredential } from './credentials';
2525

2626
/**
2727
* Enumeration of Firebase Auth error codes.
28-
*
29-
* @public
3028
*/
3129
export const enum AuthErrorCode {
3230
ADMIN_ONLY_OPERATION = 'admin-restricted-operation',
@@ -433,3 +431,112 @@ export const _DEFAULT_AUTH_ERROR_FACTORY = new ErrorFactory<
433431
AuthErrorCode,
434432
AuthErrorParams
435433
>('auth', 'Firebase', _prodErrorMap());
434+
435+
/**
436+
* A map of potential Auth error codes, for easier comparison with errors
437+
* thrown by the SDK.
438+
*
439+
* @remarks
440+
* Note that you can't tree-shake individual keys
441+
* in the map, so by using the map you might substantially increase your
442+
* bundle size.
443+
*
444+
* @public
445+
*/
446+
export const AUTH_ERROR_CODES_MAP_DO_NOT_USE_INTERNALLY = {
447+
ADMIN_ONLY_OPERATION: 'auth/admin-restricted-operation',
448+
ARGUMENT_ERROR: 'auth/argument-error',
449+
APP_NOT_AUTHORIZED: 'auth/app-not-authorized',
450+
APP_NOT_INSTALLED: 'auth/app-not-installed',
451+
CAPTCHA_CHECK_FAILED: 'auth/captcha-check-failed',
452+
CODE_EXPIRED: 'auth/code-expired',
453+
CORDOVA_NOT_READY: 'auth/cordova-not-ready',
454+
CORS_UNSUPPORTED: 'auth/cors-unsupported',
455+
CREDENTIAL_ALREADY_IN_USE: 'auth/credential-already-in-use',
456+
CREDENTIAL_MISMATCH: 'auth/custom-token-mismatch',
457+
CREDENTIAL_TOO_OLD_LOGIN_AGAIN: 'auth/requires-recent-login',
458+
DEPENDENT_SDK_INIT_BEFORE_AUTH: 'auth/dependent-sdk-initialized-before-auth',
459+
DYNAMIC_LINK_NOT_ACTIVATED: 'auth/dynamic-link-not-activated',
460+
EMAIL_CHANGE_NEEDS_VERIFICATION: 'auth/email-change-needs-verification',
461+
EMAIL_EXISTS: 'auth/email-already-in-use',
462+
EMULATOR_CONFIG_FAILED: 'auth/emulator-config-failed',
463+
EXPIRED_OOB_CODE: 'auth/expired-action-code',
464+
EXPIRED_POPUP_REQUEST: 'auth/cancelled-popup-request',
465+
INTERNAL_ERROR: 'auth/internal-error',
466+
INVALID_API_KEY: 'auth/invalid-api-key',
467+
INVALID_APP_CREDENTIAL: 'auth/invalid-app-credential',
468+
INVALID_APP_ID: 'auth/invalid-app-id',
469+
INVALID_AUTH: 'auth/invalid-user-token',
470+
INVALID_AUTH_EVENT: 'auth/invalid-auth-event',
471+
INVALID_CERT_HASH: 'auth/invalid-cert-hash',
472+
INVALID_CODE: 'auth/invalid-verification-code',
473+
INVALID_CONTINUE_URI: 'auth/invalid-continue-uri',
474+
INVALID_CORDOVA_CONFIGURATION: 'auth/invalid-cordova-configuration',
475+
INVALID_CUSTOM_TOKEN: 'auth/invalid-custom-token',
476+
INVALID_DYNAMIC_LINK_DOMAIN: 'auth/invalid-dynamic-link-domain',
477+
INVALID_EMAIL: 'auth/invalid-email',
478+
INVALID_EMULATOR_SCHEME: 'auth/invalid-emulator-scheme',
479+
INVALID_IDP_RESPONSE: 'auth/invalid-credential',
480+
INVALID_MESSAGE_PAYLOAD: 'auth/invalid-message-payload',
481+
INVALID_MFA_SESSION: 'auth/invalid-multi-factor-session',
482+
INVALID_OAUTH_CLIENT_ID: 'auth/invalid-oauth-client-id',
483+
INVALID_OAUTH_PROVIDER: 'auth/invalid-oauth-provider',
484+
INVALID_OOB_CODE: 'auth/invalid-action-code',
485+
INVALID_ORIGIN: 'auth/unauthorized-domain',
486+
INVALID_PASSWORD: 'auth/wrong-password',
487+
INVALID_PERSISTENCE: 'auth/invalid-persistence-type',
488+
INVALID_PHONE_NUMBER: 'auth/invalid-phone-number',
489+
INVALID_PROVIDER_ID: 'auth/invalid-provider-id',
490+
INVALID_RECIPIENT_EMAIL: 'auth/invalid-recipient-email',
491+
INVALID_SENDER: 'auth/invalid-sender',
492+
INVALID_SESSION_INFO: 'auth/invalid-verification-id',
493+
INVALID_TENANT_ID: 'auth/invalid-tenant-id',
494+
MFA_INFO_NOT_FOUND: 'auth/multi-factor-info-not-found',
495+
MFA_REQUIRED: 'auth/multi-factor-auth-required',
496+
MISSING_ANDROID_PACKAGE_NAME: 'auth/missing-android-pkg-name',
497+
MISSING_APP_CREDENTIAL: 'auth/missing-app-credential',
498+
MISSING_AUTH_DOMAIN: 'auth/auth-domain-config-required',
499+
MISSING_CODE: 'auth/missing-verification-code',
500+
MISSING_CONTINUE_URI: 'auth/missing-continue-uri',
501+
MISSING_IFRAME_START: 'auth/missing-iframe-start',
502+
MISSING_IOS_BUNDLE_ID: 'auth/missing-ios-bundle-id',
503+
MISSING_OR_INVALID_NONCE: 'auth/missing-or-invalid-nonce',
504+
MISSING_MFA_INFO: 'auth/missing-multi-factor-info',
505+
MISSING_MFA_SESSION: 'auth/missing-multi-factor-session',
506+
MISSING_PHONE_NUMBER: 'auth/missing-phone-number',
507+
MISSING_SESSION_INFO: 'auth/missing-verification-id',
508+
MODULE_DESTROYED: 'auth/app-deleted',
509+
NEED_CONFIRMATION: 'auth/account-exists-with-different-credential',
510+
NETWORK_REQUEST_FAILED: 'auth/network-request-failed',
511+
NULL_USER: 'auth/null-user',
512+
NO_AUTH_EVENT: 'auth/no-auth-event',
513+
NO_SUCH_PROVIDER: 'auth/no-such-provider',
514+
OPERATION_NOT_ALLOWED: 'auth/operation-not-allowed',
515+
OPERATION_NOT_SUPPORTED: 'auth/operation-not-supported-in-this-environment',
516+
POPUP_BLOCKED: 'auth/popup-blocked',
517+
POPUP_CLOSED_BY_USER: 'auth/popup-closed-by-user',
518+
PROVIDER_ALREADY_LINKED: 'auth/provider-already-linked',
519+
QUOTA_EXCEEDED: 'auth/quota-exceeded',
520+
REDIRECT_CANCELLED_BY_USER: 'auth/redirect-cancelled-by-user',
521+
REDIRECT_OPERATION_PENDING: 'auth/redirect-operation-pending',
522+
REJECTED_CREDENTIAL: 'auth/rejected-credential',
523+
SECOND_FACTOR_ALREADY_ENROLLED: 'auth/second-factor-already-in-use',
524+
SECOND_FACTOR_LIMIT_EXCEEDED: 'auth/maximum-second-factor-count-exceeded',
525+
TENANT_ID_MISMATCH: 'auth/tenant-id-mismatch',
526+
TIMEOUT: 'auth/timeout',
527+
TOKEN_EXPIRED: 'auth/user-token-expired',
528+
TOO_MANY_ATTEMPTS_TRY_LATER: 'auth/too-many-requests',
529+
UNAUTHORIZED_DOMAIN: 'auth/unauthorized-continue-uri',
530+
UNSUPPORTED_FIRST_FACTOR: 'auth/unsupported-first-factor',
531+
UNSUPPORTED_PERSISTENCE: 'auth/unsupported-persistence-type',
532+
UNSUPPORTED_TENANT_OPERATION: 'auth/unsupported-tenant-operation',
533+
UNVERIFIED_EMAIL: 'auth/unverified-email',
534+
USER_CANCELLED: 'auth/user-cancelled',
535+
USER_DELETED: 'auth/user-not-found',
536+
USER_DISABLED: 'auth/user-disabled',
537+
USER_MISMATCH: 'auth/user-mismatch',
538+
USER_SIGNED_OUT: 'auth/user-signed-out',
539+
WEAK_PASSWORD: 'auth/weak-password',
540+
WEB_STORAGE_UNSUPPORTED: 'auth/web-storage-unsupported',
541+
ALREADY_INITIALIZED: 'auth/already-initialized'
542+
} as const;

packages-exp/auth-exp/src/core/index.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ import {
2626
Unsubscribe
2727
} from '../model/public_types';
2828

29-
export { debugErrorMap, prodErrorMap } from './errors';
29+
export {
30+
debugErrorMap,
31+
prodErrorMap,
32+
AUTH_ERROR_CODES_MAP_DO_NOT_USE_INTERNALLY as AuthErrorCodes
33+
} from './errors';
3034

3135
// Non-optional auth methods.
3236
/**

0 commit comments

Comments
 (0)