@firebase/auth 1.3.0-canary.e5b96d77c → 1.3.0-canary.f002ef36a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/dist/auth-public.d.ts +25 -4
  2. package/dist/auth.d.ts +25 -4
  3. package/dist/browser-cjs/{index-23160221.js → index-3d97c204.js} +133 -127
  4. package/dist/browser-cjs/index-3d97c204.js.map +1 -0
  5. package/dist/browser-cjs/index.js +1 -1
  6. package/dist/browser-cjs/internal.js +1 -1
  7. package/dist/browser-cjs/src/api/authentication/recaptcha.d.ts +2 -2
  8. package/dist/browser-cjs/src/api/index.d.ts +10 -0
  9. package/dist/browser-cjs/src/platform_browser/recaptcha/recaptcha.d.ts +18 -3
  10. package/dist/browser-cjs/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +3 -0
  11. package/dist/cordova/index.js +2 -2
  12. package/dist/cordova/internal.js +2 -2
  13. package/dist/cordova/{popup_redirect-c751978d.js → popup_redirect-9281c39f.js} +183 -214
  14. package/dist/cordova/popup_redirect-9281c39f.js.map +1 -0
  15. package/dist/cordova/src/api/authentication/recaptcha.d.ts +2 -2
  16. package/dist/cordova/src/api/index.d.ts +10 -0
  17. package/dist/cordova/src/platform_browser/recaptcha/recaptcha.d.ts +18 -3
  18. package/dist/cordova/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +3 -0
  19. package/dist/esm2017/{index-3fbffe07.js → index-3000f55e.js} +133 -127
  20. package/dist/esm2017/index-3000f55e.js.map +1 -0
  21. package/dist/esm2017/index.js +1 -1
  22. package/dist/esm2017/internal.js +2 -2
  23. package/dist/esm2017/src/api/authentication/recaptcha.d.ts +2 -2
  24. package/dist/esm2017/src/api/index.d.ts +10 -0
  25. package/dist/esm2017/src/platform_browser/recaptcha/recaptcha.d.ts +18 -3
  26. package/dist/esm2017/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +3 -0
  27. package/dist/esm5/{index-fad8f63a.js → index-764f9bd9.js} +183 -214
  28. package/dist/esm5/index-764f9bd9.js.map +1 -0
  29. package/dist/esm5/index.js +1 -1
  30. package/dist/esm5/internal.js +2 -2
  31. package/dist/esm5/src/api/authentication/recaptcha.d.ts +2 -2
  32. package/dist/esm5/src/api/index.d.ts +10 -0
  33. package/dist/esm5/src/platform_browser/recaptcha/recaptcha.d.ts +18 -3
  34. package/dist/esm5/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +3 -0
  35. package/dist/index.webworker.esm5.js +141 -172
  36. package/dist/index.webworker.esm5.js.map +1 -1
  37. package/dist/node/index.js +1 -1
  38. package/dist/node/internal.js +1 -1
  39. package/dist/node/src/api/authentication/recaptcha.d.ts +2 -2
  40. package/dist/node/src/api/index.d.ts +10 -0
  41. package/dist/node/src/platform_browser/recaptcha/recaptcha.d.ts +18 -3
  42. package/dist/node/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +3 -0
  43. package/dist/node/{totp-21765a38.js → totp-359f3930.js} +179 -210
  44. package/dist/node/totp-359f3930.js.map +1 -0
  45. package/dist/node-esm/index.js +1 -1
  46. package/dist/node-esm/internal.js +2 -2
  47. package/dist/node-esm/src/api/authentication/recaptcha.d.ts +2 -2
  48. package/dist/node-esm/src/api/index.d.ts +10 -0
  49. package/dist/node-esm/src/platform_browser/recaptcha/recaptcha.d.ts +18 -3
  50. package/dist/node-esm/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +3 -0
  51. package/dist/node-esm/{totp-0edda768.js → totp-3e8532c1.js} +129 -123
  52. package/dist/node-esm/totp-3e8532c1.js.map +1 -0
  53. package/dist/rn/{index-7891a42a.js → index-fef1349d.js} +183 -214
  54. package/dist/rn/index-fef1349d.js.map +1 -0
  55. package/dist/rn/index.js +1 -1
  56. package/dist/rn/internal.js +1 -1
  57. package/dist/rn/src/api/authentication/recaptcha.d.ts +2 -2
  58. package/dist/rn/src/api/index.d.ts +10 -0
  59. package/dist/rn/src/platform_browser/recaptcha/recaptcha.d.ts +18 -3
  60. package/dist/rn/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +3 -0
  61. package/dist/src/api/authentication/recaptcha.d.ts +2 -2
  62. package/dist/src/api/index.d.ts +10 -0
  63. package/dist/src/platform_browser/recaptcha/recaptcha.d.ts +18 -3
  64. package/dist/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +3 -0
  65. package/package.json +12 -12
  66. package/dist/browser-cjs/index-23160221.js.map +0 -1
  67. package/dist/cordova/popup_redirect-c751978d.js.map +0 -1
  68. package/dist/esm2017/index-3fbffe07.js.map +0 -1
  69. package/dist/esm5/index-fad8f63a.js.map +0 -1
  70. package/dist/node/totp-21765a38.js.map +0 -1
  71. package/dist/node-esm/totp-0edda768.js.map +0 -1
  72. package/dist/rn/index-7891a42a.js.map +0 -1
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var totp = require('./totp-21765a38.js');
5
+ var totp = require('./totp-359f3930.js');
6
6
  require('tslib');
7
7
  require('@firebase/util');
8
8
  require('@firebase/app');
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var totp = require('./totp-21765a38.js');
5
+ var totp = require('./totp-359f3930.js');
6
6
  var tslib = require('tslib');
7
7
  var util = require('@firebase/util');
8
8
  var app = require('@firebase/app');
@@ -22,13 +22,13 @@ interface GetRecaptchaConfigRequest {
22
22
  clientType?: RecaptchaClientType;
23
23
  version?: RecaptchaVersion;
24
24
  }
25
- interface RecaptchaEnforcementState {
25
+ export interface RecaptchaEnforcementProviderState {
26
26
  provider: string;
27
27
  enforcementState: string;
28
28
  }
29
29
  export interface GetRecaptchaConfigResponse {
30
30
  recaptchaKey: string;
31
- recaptchaEnforcementState: RecaptchaEnforcementState[];
31
+ recaptchaEnforcementState: RecaptchaEnforcementProviderState[];
32
32
  }
33
33
  export declare function getRecaptchaConfig(auth: Auth, request: GetRecaptchaConfigRequest): Promise<GetRecaptchaConfigResponse>;
34
34
  export {};
@@ -69,6 +69,15 @@ export declare const enum RecaptchaActionName {
69
69
  GET_OOB_CODE = "getOobCode",
70
70
  SIGN_UP_PASSWORD = "signUpPassword"
71
71
  }
72
+ export declare const enum EnforcementState {
73
+ ENFORCE = "ENFORCE",
74
+ AUDIT = "AUDIT",
75
+ OFF = "OFF",
76
+ ENFORCEMENT_STATE_UNSPECIFIED = "ENFORCEMENT_STATE_UNSPECIFIED"
77
+ }
78
+ export declare const enum RecaptchaProvider {
79
+ EMAIL_PASSWORD_PROVIDER = "EMAIL_PASSWORD_PROVIDER"
80
+ }
72
81
  export declare const DEFAULT_API_TIMEOUT_MS: Delay;
73
82
  export declare function _addTidIfNecessary<T extends {
74
83
  tenantId?: string;
@@ -77,6 +86,7 @@ export declare function _performApiRequest<T, V>(auth: Auth, method: HttpMethod,
77
86
  export declare function _performFetchWithErrorHandling<V>(auth: Auth, customErrorMap: Partial<ServerErrorMap<ServerError>>, fetchFn: () => Promise<Response>): Promise<V>;
78
87
  export declare function _performSignInRequest<T, V extends IdTokenResponse>(auth: Auth, method: HttpMethod, path: Endpoint, request?: T, customErrorMap?: Partial<ServerErrorMap<ServerError>>): Promise<V>;
79
88
  export declare function _getFinalTarget(auth: Auth, host: string, path: string, query: string): string;
89
+ export declare function _parseEnforcementState(enforcementStateStr: string): EnforcementState;
80
90
  interface PotentialResponse extends IdTokenResponse {
81
91
  email?: string;
82
92
  phoneNumber?: string;
@@ -15,7 +15,8 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  import { RecaptchaParameters } from '../../model/public_types';
18
- import { GetRecaptchaConfigResponse } from '../../api/authentication/recaptcha';
18
+ import { GetRecaptchaConfigResponse, RecaptchaEnforcementProviderState } from '../../api/authentication/recaptcha';
19
+ import { EnforcementState } from '../../api/index';
19
20
  export interface Recaptcha {
20
21
  render: (container: HTMLElement, parameters: RecaptchaParameters) => number;
21
22
  getResponse: (id: number) => string;
@@ -49,8 +50,22 @@ export declare class RecaptchaConfig {
49
50
  */
50
51
  siteKey: string;
51
52
  /**
52
- * The reCAPTCHA enablement status of the {@link EmailAuthProvider} for the current tenant.
53
+ * The list of providers and their enablement status for reCAPTCHA Enterprise.
53
54
  */
54
- emailPasswordEnabled: boolean;
55
+ recaptchaEnforcementState: RecaptchaEnforcementProviderState[];
55
56
  constructor(response: GetRecaptchaConfigResponse);
57
+ /**
58
+ * Returns the reCAPTCHA Enterprise enforcement state for the given provider.
59
+ *
60
+ * @param providerStr - The provider whose enforcement state is to be returned.
61
+ * @returns The reCAPTCHA Enterprise enforcement state for the given provider.
62
+ */
63
+ getProviderEnforcementState(providerStr: string): EnforcementState | null;
64
+ /**
65
+ * Returns true if the reCAPTCHA Enterprise enforcement state for the provider is set to ENFORCE or AUDIT.
66
+ *
67
+ * @param providerStr - The provider whose enablement state is to be returned.
68
+ * @returns Whether or not reCAPTCHA Enterprise protection is enabled for the given provider.
69
+ */
70
+ isProviderEnabled(providerStr: string): boolean;
56
71
  }
@@ -39,4 +39,7 @@ export declare class RecaptchaEnterpriseVerifier {
39
39
  verify(action?: string, forceRefresh?: boolean): Promise<string>;
40
40
  }
41
41
  export declare function injectRecaptchaFields<T>(auth: AuthInternal, request: T, action: RecaptchaActionName, captchaResp?: boolean): Promise<T>;
42
+ declare type ActionMethod<TRequest, TResponse> = (auth: Auth, request: TRequest) => Promise<TResponse>;
43
+ export declare function handleRecaptchaFlow<TRequest, TResponse>(authInstance: AuthInternal, request: TRequest, actionName: RecaptchaActionName, actionMethod: ActionMethod<TRequest, TResponse>): Promise<TResponse>;
42
44
  export declare function _initializeRecaptchaConfig(auth: Auth): Promise<void>;
45
+ export {};
@@ -126,49 +126,6 @@ var ActionCodeOperation = {
126
126
  VERIFY_EMAIL: 'VERIFY_EMAIL'
127
127
  };
128
128
 
129
- /**
130
- * @license
131
- * Copyright 2020 Google LLC
132
- *
133
- * Licensed under the Apache License, Version 2.0 (the "License");
134
- * you may not use this file except in compliance with the License.
135
- * You may obtain a copy of the License at
136
- *
137
- * http://www.apache.org/licenses/LICENSE-2.0
138
- *
139
- * Unless required by applicable law or agreed to in writing, software
140
- * distributed under the License is distributed on an "AS IS" BASIS,
141
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
142
- * See the License for the specific language governing permissions and
143
- * limitations under the License.
144
- */
145
- function isEnterprise(grecaptcha) {
146
- return (grecaptcha !== undefined &&
147
- grecaptcha.enterprise !== undefined);
148
- }
149
- var RecaptchaConfig = /** @class */ (function () {
150
- function RecaptchaConfig(response) {
151
- /**
152
- * The reCAPTCHA site key.
153
- */
154
- this.siteKey = '';
155
- /**
156
- * The reCAPTCHA enablement status of the {@link EmailAuthProvider} for the current tenant.
157
- */
158
- this.emailPasswordEnabled = false;
159
- if (response.recaptchaKey === undefined) {
160
- throw new Error('recaptchaKey undefined');
161
- }
162
- // Example response.recaptchaKey: "projects/proj123/keys/sitekey123"
163
- this.siteKey = response.recaptchaKey.split('/')[3];
164
- this.emailPasswordEnabled = response.recaptchaEnforcementState.some(function (enforcementState) {
165
- return enforcementState.provider === 'EMAIL_PASSWORD_PROVIDER' &&
166
- enforcementState.enforcementState !== 'OFF';
167
- });
168
- }
169
- return RecaptchaConfig;
170
- }());
171
-
172
129
  /**
173
130
  * @license
174
131
  * Copyright 2020 Google LLC
@@ -799,6 +756,12 @@ var FetchProvider = /** @class */ (function () {
799
756
  if (typeof self !== 'undefined' && 'fetch' in self) {
800
757
  return self.fetch;
801
758
  }
759
+ if (typeof globalThis !== 'undefined' && globalThis.fetch) {
760
+ return globalThis.fetch;
761
+ }
762
+ if (typeof fetch !== 'undefined') {
763
+ return fetch;
764
+ }
802
765
  debugFail('Could not find fetch implementation, make sure you call FetchProvider.initialize() with an appropriate polyfill');
803
766
  };
804
767
  FetchProvider.headers = function () {
@@ -808,6 +771,12 @@ var FetchProvider = /** @class */ (function () {
808
771
  if (typeof self !== 'undefined' && 'Headers' in self) {
809
772
  return self.Headers;
810
773
  }
774
+ if (typeof globalThis !== 'undefined' && globalThis.Headers) {
775
+ return globalThis.Headers;
776
+ }
777
+ if (typeof Headers !== 'undefined') {
778
+ return Headers;
779
+ }
811
780
  debugFail('Could not find Headers implementation, make sure you call FetchProvider.initialize() with an appropriate polyfill');
812
781
  };
813
782
  FetchProvider.response = function () {
@@ -817,6 +786,12 @@ var FetchProvider = /** @class */ (function () {
817
786
  if (typeof self !== 'undefined' && 'Response' in self) {
818
787
  return self.Response;
819
788
  }
789
+ if (typeof globalThis !== 'undefined' && globalThis.Response) {
790
+ return globalThis.Response;
791
+ }
792
+ if (typeof Response !== 'undefined') {
793
+ return Response;
794
+ }
820
795
  debugFail('Could not find Response implementation, make sure you call FetchProvider.initialize() with an appropriate polyfill');
821
796
  };
822
797
  return FetchProvider;
@@ -1069,6 +1044,18 @@ function _getFinalTarget(auth, host, path, query) {
1069
1044
  }
1070
1045
  return _emulatorUrl(auth.config, base);
1071
1046
  }
1047
+ function _parseEnforcementState(enforcementStateStr) {
1048
+ switch (enforcementStateStr) {
1049
+ case 'ENFORCE':
1050
+ return "ENFORCE" /* EnforcementState.ENFORCE */;
1051
+ case 'AUDIT':
1052
+ return "AUDIT" /* EnforcementState.AUDIT */;
1053
+ case 'OFF':
1054
+ return "OFF" /* EnforcementState.OFF */;
1055
+ default:
1056
+ return "ENFORCEMENT_STATE_UNSPECIFIED" /* EnforcementState.ENFORCEMENT_STATE_UNSPECIFIED */;
1057
+ }
1058
+ }
1072
1059
  var NetworkTimeout = /** @class */ (function () {
1073
1060
  function NetworkTimeout(auth) {
1074
1061
  var _this = this;
@@ -1104,6 +1091,77 @@ function _makeTaggedError(auth, code, response) {
1104
1091
  return error;
1105
1092
  }
1106
1093
 
1094
+ /**
1095
+ * @license
1096
+ * Copyright 2020 Google LLC
1097
+ *
1098
+ * Licensed under the Apache License, Version 2.0 (the "License");
1099
+ * you may not use this file except in compliance with the License.
1100
+ * You may obtain a copy of the License at
1101
+ *
1102
+ * http://www.apache.org/licenses/LICENSE-2.0
1103
+ *
1104
+ * Unless required by applicable law or agreed to in writing, software
1105
+ * distributed under the License is distributed on an "AS IS" BASIS,
1106
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1107
+ * See the License for the specific language governing permissions and
1108
+ * limitations under the License.
1109
+ */
1110
+ function isEnterprise(grecaptcha) {
1111
+ return (grecaptcha !== undefined &&
1112
+ grecaptcha.enterprise !== undefined);
1113
+ }
1114
+ var RecaptchaConfig = /** @class */ (function () {
1115
+ function RecaptchaConfig(response) {
1116
+ /**
1117
+ * The reCAPTCHA site key.
1118
+ */
1119
+ this.siteKey = '';
1120
+ /**
1121
+ * The list of providers and their enablement status for reCAPTCHA Enterprise.
1122
+ */
1123
+ this.recaptchaEnforcementState = [];
1124
+ if (response.recaptchaKey === undefined) {
1125
+ throw new Error('recaptchaKey undefined');
1126
+ }
1127
+ // Example response.recaptchaKey: "projects/proj123/keys/sitekey123"
1128
+ this.siteKey = response.recaptchaKey.split('/')[3];
1129
+ this.recaptchaEnforcementState = response.recaptchaEnforcementState;
1130
+ }
1131
+ /**
1132
+ * Returns the reCAPTCHA Enterprise enforcement state for the given provider.
1133
+ *
1134
+ * @param providerStr - The provider whose enforcement state is to be returned.
1135
+ * @returns The reCAPTCHA Enterprise enforcement state for the given provider.
1136
+ */
1137
+ RecaptchaConfig.prototype.getProviderEnforcementState = function (providerStr) {
1138
+ if (!this.recaptchaEnforcementState ||
1139
+ this.recaptchaEnforcementState.length === 0) {
1140
+ return null;
1141
+ }
1142
+ for (var _i = 0, _a = this.recaptchaEnforcementState; _i < _a.length; _i++) {
1143
+ var recaptchaEnforcementState = _a[_i];
1144
+ if (recaptchaEnforcementState.provider &&
1145
+ recaptchaEnforcementState.provider === providerStr) {
1146
+ return _parseEnforcementState(recaptchaEnforcementState.enforcementState);
1147
+ }
1148
+ }
1149
+ return null;
1150
+ };
1151
+ /**
1152
+ * Returns true if the reCAPTCHA Enterprise enforcement state for the provider is set to ENFORCE or AUDIT.
1153
+ *
1154
+ * @param providerStr - The provider whose enablement state is to be returned.
1155
+ * @returns Whether or not reCAPTCHA Enterprise protection is enabled for the given provider.
1156
+ */
1157
+ RecaptchaConfig.prototype.isProviderEnabled = function (providerStr) {
1158
+ return (this.getProviderEnforcementState(providerStr) ===
1159
+ "ENFORCE" /* EnforcementState.ENFORCE */ ||
1160
+ this.getProviderEnforcementState(providerStr) === "AUDIT" /* EnforcementState.AUDIT */);
1161
+ };
1162
+ return RecaptchaConfig;
1163
+ }());
1164
+
1107
1165
  /**
1108
1166
  * @license
1109
1167
  * Copyright 2020 Google LLC
@@ -3768,6 +3826,39 @@ function injectRecaptchaFields(auth, request, action, captchaResp) {
3768
3826
  });
3769
3827
  });
3770
3828
  }
3829
+ function handleRecaptchaFlow(authInstance, request, actionName, actionMethod) {
3830
+ var _a;
3831
+ return tslib.__awaiter(this, void 0, void 0, function () {
3832
+ var requestWithRecaptcha;
3833
+ var _this = this;
3834
+ return tslib.__generator(this, function (_b) {
3835
+ switch (_b.label) {
3836
+ case 0:
3837
+ if (!((_a = authInstance
3838
+ ._getRecaptchaConfig()) === null || _a === void 0 ? void 0 : _a.isProviderEnabled("EMAIL_PASSWORD_PROVIDER" /* RecaptchaProvider.EMAIL_PASSWORD_PROVIDER */))) return [3 /*break*/, 2];
3839
+ return [4 /*yield*/, injectRecaptchaFields(authInstance, request, actionName, actionName === "getOobCode" /* RecaptchaActionName.GET_OOB_CODE */)];
3840
+ case 1:
3841
+ requestWithRecaptcha = _b.sent();
3842
+ return [2 /*return*/, actionMethod(authInstance, requestWithRecaptcha)];
3843
+ case 2: return [2 /*return*/, actionMethod(authInstance, request).catch(function (error) { return tslib.__awaiter(_this, void 0, void 0, function () {
3844
+ var requestWithRecaptcha;
3845
+ return tslib.__generator(this, function (_a) {
3846
+ switch (_a.label) {
3847
+ case 0:
3848
+ if (!(error.code === "auth/".concat("missing-recaptcha-token" /* AuthErrorCode.MISSING_RECAPTCHA_TOKEN */))) return [3 /*break*/, 2];
3849
+ console.log("".concat(actionName, " is protected by reCAPTCHA Enterprise for this project. Automatically triggering the reCAPTCHA flow and restarting the flow."));
3850
+ return [4 /*yield*/, injectRecaptchaFields(authInstance, request, actionName, actionName === "getOobCode" /* RecaptchaActionName.GET_OOB_CODE */)];
3851
+ case 1:
3852
+ requestWithRecaptcha = _a.sent();
3853
+ return [2 /*return*/, actionMethod(authInstance, requestWithRecaptcha)];
3854
+ case 2: return [2 /*return*/, Promise.reject(error)];
3855
+ }
3856
+ });
3857
+ }); })];
3858
+ }
3859
+ });
3860
+ });
3861
+ }
3771
3862
  function _initializeRecaptchaConfig(auth) {
3772
3863
  return tslib.__awaiter(this, void 0, void 0, function () {
3773
3864
  var authInternal, response, config, verifier;
@@ -3788,7 +3879,7 @@ function _initializeRecaptchaConfig(auth) {
3788
3879
  else {
3789
3880
  authInternal._tenantRecaptchaConfigs[authInternal.tenantId] = config;
3790
3881
  }
3791
- if (config.emailPasswordEnabled) {
3882
+ if (config.isProviderEnabled("EMAIL_PASSWORD_PROVIDER" /* RecaptchaProvider.EMAIL_PASSWORD_PROVIDER */)) {
3792
3883
  verifier = new RecaptchaEnterpriseVerifier(authInternal);
3793
3884
  void verifier.verify();
3794
3885
  }
@@ -4254,55 +4345,27 @@ var EmailAuthCredential = /** @class */ (function (_super) {
4254
4345
  };
4255
4346
  /** @internal */
4256
4347
  EmailAuthCredential.prototype._getIdTokenResponse = function (auth) {
4257
- var _a;
4258
4348
  return tslib.__awaiter(this, void 0, void 0, function () {
4259
- var _b, request_1, requestWithRecaptcha;
4260
- var _this = this;
4261
- return tslib.__generator(this, function (_c) {
4262
- switch (_c.label) {
4263
- case 0:
4264
- _b = this.signInMethod;
4265
- switch (_b) {
4266
- case "password" /* SignInMethod.EMAIL_PASSWORD */: return [3 /*break*/, 1];
4267
- case "emailLink" /* SignInMethod.EMAIL_LINK */: return [3 /*break*/, 4];
4268
- }
4269
- return [3 /*break*/, 5];
4270
- case 1:
4271
- request_1 = {
4349
+ var request;
4350
+ return tslib.__generator(this, function (_a) {
4351
+ switch (this.signInMethod) {
4352
+ case "password" /* SignInMethod.EMAIL_PASSWORD */:
4353
+ request = {
4272
4354
  returnSecureToken: true,
4273
4355
  email: this._email,
4274
4356
  password: this._password,
4275
4357
  clientType: "CLIENT_TYPE_WEB" /* RecaptchaClientType.WEB */
4276
4358
  };
4277
- if (!((_a = auth._getRecaptchaConfig()) === null || _a === void 0 ? void 0 : _a.emailPasswordEnabled)) return [3 /*break*/, 3];
4278
- return [4 /*yield*/, injectRecaptchaFields(auth, request_1, "signInWithPassword" /* RecaptchaActionName.SIGN_IN_WITH_PASSWORD */)];
4279
- case 2:
4280
- requestWithRecaptcha = _c.sent();
4281
- return [2 /*return*/, signInWithPassword(auth, requestWithRecaptcha)];
4282
- case 3: return [2 /*return*/, signInWithPassword(auth, request_1).catch(function (error) { return tslib.__awaiter(_this, void 0, void 0, function () {
4283
- var requestWithRecaptcha;
4284
- return tslib.__generator(this, function (_a) {
4285
- switch (_a.label) {
4286
- case 0:
4287
- if (!(error.code === "auth/".concat("missing-recaptcha-token" /* AuthErrorCode.MISSING_RECAPTCHA_TOKEN */))) return [3 /*break*/, 2];
4288
- console.log('Sign-in with email address and password is protected by reCAPTCHA for this project. Automatically triggering the reCAPTCHA flow and restarting the sign-in flow.');
4289
- return [4 /*yield*/, injectRecaptchaFields(auth, request_1, "signInWithPassword" /* RecaptchaActionName.SIGN_IN_WITH_PASSWORD */)];
4290
- case 1:
4291
- requestWithRecaptcha = _a.sent();
4292
- return [2 /*return*/, signInWithPassword(auth, requestWithRecaptcha)];
4293
- case 2: return [2 /*return*/, Promise.reject(error)];
4294
- }
4295
- });
4296
- }); })];
4297
- case 4: return [2 /*return*/, signInWithEmailLink$1(auth, {
4298
- email: this._email,
4299
- oobCode: this._password
4300
- })];
4301
- case 5:
4359
+ return [2 /*return*/, handleRecaptchaFlow(auth, request, "signInWithPassword" /* RecaptchaActionName.SIGN_IN_WITH_PASSWORD */, signInWithPassword)];
4360
+ case "emailLink" /* SignInMethod.EMAIL_LINK */:
4361
+ return [2 /*return*/, signInWithEmailLink$1(auth, {
4362
+ email: this._email,
4363
+ oobCode: this._password
4364
+ })];
4365
+ default:
4302
4366
  _fail(auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
4303
- _c.label = 6;
4304
- case 6: return [2 /*return*/];
4305
4367
  }
4368
+ return [2 /*return*/];
4306
4369
  });
4307
4370
  });
4308
4371
  };
@@ -6512,12 +6575,10 @@ function recachePasswordPolicy(auth) {
6512
6575
  * @public
6513
6576
  */
6514
6577
  function sendPasswordResetEmail(auth, email, actionCodeSettings) {
6515
- var _a;
6516
6578
  return tslib.__awaiter(this, void 0, void 0, function () {
6517
- var authInternal, request, requestWithRecaptcha;
6518
- var _this = this;
6519
- return tslib.__generator(this, function (_b) {
6520
- switch (_b.label) {
6579
+ var authInternal, request;
6580
+ return tslib.__generator(this, function (_a) {
6581
+ switch (_a.label) {
6521
6582
  case 0:
6522
6583
  authInternal = _castAuth(auth);
6523
6584
  request = {
@@ -6525,48 +6586,13 @@ function sendPasswordResetEmail(auth, email, actionCodeSettings) {
6525
6586
  email: email,
6526
6587
  clientType: "CLIENT_TYPE_WEB" /* RecaptchaClientType.WEB */
6527
6588
  };
6528
- if (!((_a = authInternal._getRecaptchaConfig()) === null || _a === void 0 ? void 0 : _a.emailPasswordEnabled)) return [3 /*break*/, 3];
6529
- return [4 /*yield*/, injectRecaptchaFields(authInternal, request, "getOobCode" /* RecaptchaActionName.GET_OOB_CODE */, true)];
6530
- case 1:
6531
- requestWithRecaptcha = _b.sent();
6532
- if (actionCodeSettings) {
6533
- _setActionCodeSettingsOnRequest(authInternal, requestWithRecaptcha, actionCodeSettings);
6534
- }
6535
- return [4 /*yield*/, sendPasswordResetEmail$1(authInternal, requestWithRecaptcha)];
6536
- case 2:
6537
- _b.sent();
6538
- return [3 /*break*/, 5];
6539
- case 3:
6540
6589
  if (actionCodeSettings) {
6541
6590
  _setActionCodeSettingsOnRequest(authInternal, request, actionCodeSettings);
6542
6591
  }
6543
- return [4 /*yield*/, sendPasswordResetEmail$1(authInternal, request)
6544
- .catch(function (error) { return tslib.__awaiter(_this, void 0, void 0, function () {
6545
- var requestWithRecaptcha;
6546
- return tslib.__generator(this, function (_a) {
6547
- switch (_a.label) {
6548
- case 0:
6549
- if (!(error.code === "auth/".concat("missing-recaptcha-token" /* AuthErrorCode.MISSING_RECAPTCHA_TOKEN */))) return [3 /*break*/, 3];
6550
- console.log('Password resets are protected by reCAPTCHA for this project. Automatically triggering the reCAPTCHA flow and restarting the password reset flow.');
6551
- return [4 /*yield*/, injectRecaptchaFields(authInternal, request, "getOobCode" /* RecaptchaActionName.GET_OOB_CODE */, true)];
6552
- case 1:
6553
- requestWithRecaptcha = _a.sent();
6554
- if (actionCodeSettings) {
6555
- _setActionCodeSettingsOnRequest(authInternal, requestWithRecaptcha, actionCodeSettings);
6556
- }
6557
- return [4 /*yield*/, sendPasswordResetEmail$1(authInternal, requestWithRecaptcha)];
6558
- case 2:
6559
- _a.sent();
6560
- return [3 /*break*/, 4];
6561
- case 3: return [2 /*return*/, Promise.reject(error)];
6562
- case 4: return [2 /*return*/];
6563
- }
6564
- });
6565
- }); })];
6566
- case 4:
6567
- _b.sent();
6568
- _b.label = 5;
6569
- case 5: return [2 /*return*/];
6592
+ return [4 /*yield*/, handleRecaptchaFlow(authInternal, request, "getOobCode" /* RecaptchaActionName.GET_OOB_CODE */, sendPasswordResetEmail$1)];
6593
+ case 1:
6594
+ _a.sent();
6595
+ return [2 /*return*/];
6570
6596
  }
6571
6597
  });
6572
6598
  });
@@ -6721,12 +6747,10 @@ function verifyPasswordResetCode(auth, code) {
6721
6747
  * @public
6722
6748
  */
6723
6749
  function createUserWithEmailAndPassword(auth, email, password) {
6724
- var _a;
6725
6750
  return tslib.__awaiter(this, void 0, void 0, function () {
6726
- var authInternal, request, signUpResponse, requestWithRecaptcha, response, userCredential;
6727
- var _this = this;
6728
- return tslib.__generator(this, function (_b) {
6729
- switch (_b.label) {
6751
+ var authInternal, request, signUpResponse, response, userCredential;
6752
+ return tslib.__generator(this, function (_a) {
6753
+ switch (_a.label) {
6730
6754
  case 0:
6731
6755
  authInternal = _castAuth(auth);
6732
6756
  request = {
@@ -6735,43 +6759,21 @@ function createUserWithEmailAndPassword(auth, email, password) {
6735
6759
  password: password,
6736
6760
  clientType: "CLIENT_TYPE_WEB" /* RecaptchaClientType.WEB */
6737
6761
  };
6738
- if (!((_a = authInternal._getRecaptchaConfig()) === null || _a === void 0 ? void 0 : _a.emailPasswordEnabled)) return [3 /*break*/, 2];
6739
- return [4 /*yield*/, injectRecaptchaFields(authInternal, request, "signUpPassword" /* RecaptchaActionName.SIGN_UP_PASSWORD */)];
6740
- case 1:
6741
- requestWithRecaptcha = _b.sent();
6742
- signUpResponse = signUp(authInternal, requestWithRecaptcha);
6743
- return [3 /*break*/, 3];
6744
- case 2:
6745
- signUpResponse = signUp(authInternal, request).catch(function (error) { return tslib.__awaiter(_this, void 0, void 0, function () {
6746
- var requestWithRecaptcha;
6747
- return tslib.__generator(this, function (_a) {
6748
- switch (_a.label) {
6749
- case 0:
6750
- if (!(error.code === "auth/".concat("missing-recaptcha-token" /* AuthErrorCode.MISSING_RECAPTCHA_TOKEN */))) return [3 /*break*/, 2];
6751
- console.log('Sign-up is protected by reCAPTCHA for this project. Automatically triggering the reCAPTCHA flow and restarting the sign-up flow.');
6752
- return [4 /*yield*/, injectRecaptchaFields(authInternal, request, "signUpPassword" /* RecaptchaActionName.SIGN_UP_PASSWORD */)];
6753
- case 1:
6754
- requestWithRecaptcha = _a.sent();
6755
- return [2 /*return*/, signUp(authInternal, requestWithRecaptcha)];
6756
- case 2: throw error;
6762
+ signUpResponse = handleRecaptchaFlow(authInternal, request, "signUpPassword" /* RecaptchaActionName.SIGN_UP_PASSWORD */, signUp);
6763
+ return [4 /*yield*/, signUpResponse.catch(function (error) {
6764
+ if (error.code === "auth/".concat("password-does-not-meet-requirements" /* AuthErrorCode.PASSWORD_DOES_NOT_MEET_REQUIREMENTS */)) {
6765
+ void recachePasswordPolicy(auth);
6757
6766
  }
6758
- });
6759
- }); });
6760
- _b.label = 3;
6761
- case 3: return [4 /*yield*/, signUpResponse.catch(function (error) {
6762
- if (error.code === "auth/".concat("password-does-not-meet-requirements" /* AuthErrorCode.PASSWORD_DOES_NOT_MEET_REQUIREMENTS */)) {
6763
- void recachePasswordPolicy(auth);
6764
- }
6765
- throw error;
6766
- })];
6767
- case 4:
6768
- response = _b.sent();
6767
+ throw error;
6768
+ })];
6769
+ case 1:
6770
+ response = _a.sent();
6769
6771
  return [4 /*yield*/, UserCredentialImpl._fromIdTokenResponse(authInternal, "signIn" /* OperationType.SIGN_IN */, response)];
6770
- case 5:
6771
- userCredential = _b.sent();
6772
+ case 2:
6773
+ userCredential = _a.sent();
6772
6774
  return [4 /*yield*/, authInternal._updateCurrentUser(userCredential.user)];
6773
- case 6:
6774
- _b.sent();
6775
+ case 3:
6776
+ _a.sent();
6775
6777
  return [2 /*return*/, userCredential];
6776
6778
  }
6777
6779
  });
@@ -6860,7 +6862,6 @@ function signInWithEmailAndPassword(auth, email, password) {
6860
6862
  * @public
6861
6863
  */
6862
6864
  function sendSignInLinkToEmail(auth, email, actionCodeSettings) {
6863
- var _a;
6864
6865
  return tslib.__awaiter(this, void 0, void 0, function () {
6865
6866
  function setActionCodeSettings(request, actionCodeSettings) {
6866
6867
  _assert(actionCodeSettings.handleCodeInApp, authInternal, "argument-error" /* AuthErrorCode.ARGUMENT_ERROR */);
@@ -6868,10 +6869,9 @@ function sendSignInLinkToEmail(auth, email, actionCodeSettings) {
6868
6869
  _setActionCodeSettingsOnRequest(authInternal, request, actionCodeSettings);
6869
6870
  }
6870
6871
  }
6871
- var authInternal, request, requestWithRecaptcha;
6872
- var _this = this;
6873
- return tslib.__generator(this, function (_b) {
6874
- switch (_b.label) {
6872
+ var authInternal, request;
6873
+ return tslib.__generator(this, function (_a) {
6874
+ switch (_a.label) {
6875
6875
  case 0:
6876
6876
  authInternal = _castAuth(auth);
6877
6877
  request = {
@@ -6879,42 +6879,11 @@ function sendSignInLinkToEmail(auth, email, actionCodeSettings) {
6879
6879
  email: email,
6880
6880
  clientType: "CLIENT_TYPE_WEB" /* RecaptchaClientType.WEB */
6881
6881
  };
6882
- if (!((_a = authInternal._getRecaptchaConfig()) === null || _a === void 0 ? void 0 : _a.emailPasswordEnabled)) return [3 /*break*/, 3];
6883
- return [4 /*yield*/, injectRecaptchaFields(authInternal, request, "getOobCode" /* RecaptchaActionName.GET_OOB_CODE */, true)];
6884
- case 1:
6885
- requestWithRecaptcha = _b.sent();
6886
- setActionCodeSettings(requestWithRecaptcha, actionCodeSettings);
6887
- return [4 /*yield*/, sendSignInLinkToEmail$1(authInternal, requestWithRecaptcha)];
6888
- case 2:
6889
- _b.sent();
6890
- return [3 /*break*/, 5];
6891
- case 3:
6892
6882
  setActionCodeSettings(request, actionCodeSettings);
6893
- return [4 /*yield*/, sendSignInLinkToEmail$1(authInternal, request)
6894
- .catch(function (error) { return tslib.__awaiter(_this, void 0, void 0, function () {
6895
- var requestWithRecaptcha;
6896
- return tslib.__generator(this, function (_a) {
6897
- switch (_a.label) {
6898
- case 0:
6899
- if (!(error.code === "auth/".concat("missing-recaptcha-token" /* AuthErrorCode.MISSING_RECAPTCHA_TOKEN */))) return [3 /*break*/, 3];
6900
- console.log('Email link sign-in is protected by reCAPTCHA for this project. Automatically triggering the reCAPTCHA flow and restarting the sign-in flow.');
6901
- return [4 /*yield*/, injectRecaptchaFields(authInternal, request, "getOobCode" /* RecaptchaActionName.GET_OOB_CODE */, true)];
6902
- case 1:
6903
- requestWithRecaptcha = _a.sent();
6904
- setActionCodeSettings(requestWithRecaptcha, actionCodeSettings);
6905
- return [4 /*yield*/, sendSignInLinkToEmail$1(authInternal, requestWithRecaptcha)];
6906
- case 2:
6907
- _a.sent();
6908
- return [3 /*break*/, 4];
6909
- case 3: return [2 /*return*/, Promise.reject(error)];
6910
- case 4: return [2 /*return*/];
6911
- }
6912
- });
6913
- }); })];
6914
- case 4:
6915
- _b.sent();
6916
- _b.label = 5;
6917
- case 5: return [2 /*return*/];
6883
+ return [4 /*yield*/, handleRecaptchaFlow(authInternal, request, "getOobCode" /* RecaptchaActionName.GET_OOB_CODE */, sendSignInLinkToEmail$1)];
6884
+ case 1:
6885
+ _a.sent();
6886
+ return [2 /*return*/];
6918
6887
  }
6919
6888
  });
6920
6889
  });
@@ -7988,7 +7957,7 @@ function multiFactor(user) {
7988
7957
  }
7989
7958
 
7990
7959
  var name = "@firebase/auth";
7991
- var version = "1.3.0-canary.e5b96d77c";
7960
+ var version = "1.3.0-canary.f002ef36a";
7992
7961
 
7993
7962
  /**
7994
7963
  * @license
@@ -8559,4 +8528,4 @@ exports.useDeviceLanguage = useDeviceLanguage;
8559
8528
  exports.validatePassword = validatePassword;
8560
8529
  exports.verifyBeforeUpdateEmail = verifyBeforeUpdateEmail;
8561
8530
  exports.verifyPasswordResetCode = verifyPasswordResetCode;
8562
- //# sourceMappingURL=totp-21765a38.js.map
8531
+ //# sourceMappingURL=totp-359f3930.js.map