@firebase/auth 0.22.0-canary.b66908df6 → 0.22.0-canary.ecb4454c3

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 (175) hide show
  1. package/dist/auth-public.d.ts +57 -0
  2. package/dist/auth.d.ts +70 -1
  3. package/dist/browser-cjs/{index-f15d4bca.js → index-2a5c9cce.js} +526 -181
  4. package/dist/browser-cjs/index-2a5c9cce.js.map +1 -0
  5. package/dist/browser-cjs/index.js +3 -2
  6. package/dist/browser-cjs/index.js.map +1 -1
  7. package/dist/browser-cjs/internal.js +3 -2
  8. package/dist/browser-cjs/internal.js.map +1 -1
  9. package/dist/browser-cjs/src/api/authentication/email_and_password.d.ts +9 -0
  10. package/dist/browser-cjs/src/api/authentication/recaptcha.d.ts +16 -0
  11. package/dist/browser-cjs/src/api/authentication/sign_up.d.ts +4 -0
  12. package/dist/browser-cjs/src/api/errors.d.ts +9 -1
  13. package/dist/browser-cjs/src/api/index.d.ts +15 -1
  14. package/dist/browser-cjs/src/core/auth/auth_impl.d.ts +5 -0
  15. package/dist/browser-cjs/src/core/errors.d.ts +17 -1
  16. package/dist/browser-cjs/src/core/index.d.ts +26 -0
  17. package/dist/browser-cjs/src/model/auth.d.ts +5 -0
  18. package/dist/browser-cjs/src/platform_browser/auth_window.d.ts +2 -2
  19. package/dist/browser-cjs/src/platform_browser/recaptcha/recaptcha.d.ts +33 -0
  20. package/dist/browser-cjs/src/platform_browser/recaptcha/recaptcha.test.d.ts +17 -0
  21. package/dist/browser-cjs/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +40 -0
  22. package/dist/browser-cjs/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.test.d.ts +17 -0
  23. package/dist/browser-cjs/src/platform_browser/recaptcha/recaptcha_mock.d.ts +16 -1
  24. package/dist/browser-cjs/test/helpers/api/helper.d.ts +2 -0
  25. package/dist/cordova/index.js +2 -2
  26. package/dist/cordova/internal.js +4 -71
  27. package/dist/cordova/internal.js.map +1 -1
  28. package/dist/cordova/{popup_redirect-6a7ae974.js → popup_redirect-710a0689.js} +660 -152
  29. package/dist/cordova/popup_redirect-710a0689.js.map +1 -0
  30. package/dist/cordova/src/api/authentication/email_and_password.d.ts +9 -0
  31. package/dist/cordova/src/api/authentication/recaptcha.d.ts +16 -0
  32. package/dist/cordova/src/api/authentication/sign_up.d.ts +4 -0
  33. package/dist/cordova/src/api/errors.d.ts +9 -1
  34. package/dist/cordova/src/api/index.d.ts +15 -1
  35. package/dist/cordova/src/core/auth/auth_impl.d.ts +5 -0
  36. package/dist/cordova/src/core/errors.d.ts +17 -1
  37. package/dist/cordova/src/core/index.d.ts +26 -0
  38. package/dist/cordova/src/model/auth.d.ts +5 -0
  39. package/dist/cordova/src/platform_browser/auth_window.d.ts +2 -2
  40. package/dist/cordova/src/platform_browser/recaptcha/recaptcha.d.ts +33 -0
  41. package/dist/cordova/src/platform_browser/recaptcha/recaptcha.test.d.ts +17 -0
  42. package/dist/cordova/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +40 -0
  43. package/dist/cordova/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.test.d.ts +17 -0
  44. package/dist/cordova/src/platform_browser/recaptcha/recaptcha_mock.d.ts +16 -1
  45. package/dist/cordova/test/helpers/api/helper.d.ts +2 -0
  46. package/dist/esm2017/{index-73d232c4.js → index-2dbc6285.js} +527 -183
  47. package/dist/esm2017/index-2dbc6285.js.map +1 -0
  48. package/dist/esm2017/index.js +2 -2
  49. package/dist/esm2017/internal.js +3 -3
  50. package/dist/esm2017/src/api/authentication/email_and_password.d.ts +9 -0
  51. package/dist/esm2017/src/api/authentication/recaptcha.d.ts +16 -0
  52. package/dist/esm2017/src/api/authentication/sign_up.d.ts +4 -0
  53. package/dist/esm2017/src/api/errors.d.ts +9 -1
  54. package/dist/esm2017/src/api/index.d.ts +15 -1
  55. package/dist/esm2017/src/core/auth/auth_impl.d.ts +5 -0
  56. package/dist/esm2017/src/core/errors.d.ts +17 -1
  57. package/dist/esm2017/src/core/index.d.ts +26 -0
  58. package/dist/esm2017/src/model/auth.d.ts +5 -0
  59. package/dist/esm2017/src/platform_browser/auth_window.d.ts +2 -2
  60. package/dist/esm2017/src/platform_browser/recaptcha/recaptcha.d.ts +33 -0
  61. package/dist/esm2017/src/platform_browser/recaptcha/recaptcha.test.d.ts +17 -0
  62. package/dist/esm2017/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +40 -0
  63. package/dist/esm2017/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.test.d.ts +17 -0
  64. package/dist/esm2017/src/platform_browser/recaptcha/recaptcha_mock.d.ts +16 -1
  65. package/dist/esm2017/test/helpers/api/helper.d.ts +2 -0
  66. package/dist/esm5/{index-612b0526.js → index-f764da84.js} +682 -241
  67. package/dist/esm5/index-f764da84.js.map +1 -0
  68. package/dist/esm5/index.js +1 -1
  69. package/dist/esm5/internal.js +2 -2
  70. package/dist/esm5/src/api/authentication/email_and_password.d.ts +9 -0
  71. package/dist/esm5/src/api/authentication/recaptcha.d.ts +16 -0
  72. package/dist/esm5/src/api/authentication/sign_up.d.ts +4 -0
  73. package/dist/esm5/src/api/errors.d.ts +9 -1
  74. package/dist/esm5/src/api/index.d.ts +15 -1
  75. package/dist/esm5/src/core/auth/auth_impl.d.ts +5 -0
  76. package/dist/esm5/src/core/errors.d.ts +17 -1
  77. package/dist/esm5/src/core/index.d.ts +26 -0
  78. package/dist/esm5/src/model/auth.d.ts +5 -0
  79. package/dist/esm5/src/platform_browser/auth_window.d.ts +2 -2
  80. package/dist/esm5/src/platform_browser/recaptcha/recaptcha.d.ts +33 -0
  81. package/dist/esm5/src/platform_browser/recaptcha/recaptcha.test.d.ts +17 -0
  82. package/dist/esm5/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +40 -0
  83. package/dist/esm5/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.test.d.ts +17 -0
  84. package/dist/esm5/src/platform_browser/recaptcha/recaptcha_mock.d.ts +16 -1
  85. package/dist/esm5/test/helpers/api/helper.d.ts +2 -0
  86. package/dist/index.webworker.esm5.js +544 -53
  87. package/dist/index.webworker.esm5.js.map +1 -1
  88. package/dist/node/index.js +2 -1
  89. package/dist/node/index.js.map +1 -1
  90. package/dist/node/internal.js +2 -1
  91. package/dist/node/internal.js.map +1 -1
  92. package/dist/node/src/api/authentication/email_and_password.d.ts +9 -0
  93. package/dist/node/src/api/authentication/recaptcha.d.ts +16 -0
  94. package/dist/node/src/api/authentication/sign_up.d.ts +4 -0
  95. package/dist/node/src/api/errors.d.ts +9 -1
  96. package/dist/node/src/api/index.d.ts +15 -1
  97. package/dist/node/src/core/auth/auth_impl.d.ts +5 -0
  98. package/dist/node/src/core/errors.d.ts +17 -1
  99. package/dist/node/src/core/index.d.ts +26 -0
  100. package/dist/node/src/model/auth.d.ts +5 -0
  101. package/dist/node/src/platform_browser/auth_window.d.ts +2 -2
  102. package/dist/node/src/platform_browser/recaptcha/recaptcha.d.ts +33 -0
  103. package/dist/node/src/platform_browser/recaptcha/recaptcha.test.d.ts +17 -0
  104. package/dist/node/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +40 -0
  105. package/dist/node/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.test.d.ts +17 -0
  106. package/dist/node/src/platform_browser/recaptcha/recaptcha_mock.d.ts +16 -1
  107. package/dist/node/test/helpers/api/helper.d.ts +2 -0
  108. package/dist/node/{totp-84316976.js → totp-b357b7fa.js} +642 -150
  109. package/dist/node/totp-b357b7fa.js.map +1 -0
  110. package/dist/node-esm/index.js +1 -1
  111. package/dist/node-esm/internal.js +2 -2
  112. package/dist/node-esm/src/api/authentication/email_and_password.d.ts +9 -0
  113. package/dist/node-esm/src/api/authentication/recaptcha.d.ts +16 -0
  114. package/dist/node-esm/src/api/authentication/sign_up.d.ts +4 -0
  115. package/dist/node-esm/src/api/errors.d.ts +9 -1
  116. package/dist/node-esm/src/api/index.d.ts +15 -1
  117. package/dist/node-esm/src/core/auth/auth_impl.d.ts +5 -0
  118. package/dist/node-esm/src/core/errors.d.ts +17 -1
  119. package/dist/node-esm/src/core/index.d.ts +26 -0
  120. package/dist/node-esm/src/model/auth.d.ts +5 -0
  121. package/dist/node-esm/src/platform_browser/auth_window.d.ts +2 -2
  122. package/dist/node-esm/src/platform_browser/recaptcha/recaptcha.d.ts +33 -0
  123. package/dist/node-esm/src/platform_browser/recaptcha/recaptcha.test.d.ts +17 -0
  124. package/dist/node-esm/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +40 -0
  125. package/dist/node-esm/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.test.d.ts +17 -0
  126. package/dist/node-esm/src/platform_browser/recaptcha/recaptcha_mock.d.ts +16 -1
  127. package/dist/node-esm/test/helpers/api/helper.d.ts +2 -0
  128. package/dist/node-esm/{totp-0e6e00b2.js → totp-501673f0.js} +514 -120
  129. package/dist/node-esm/totp-501673f0.js.map +1 -0
  130. package/dist/rn/index.js +2 -1
  131. package/dist/rn/index.js.map +1 -1
  132. package/dist/rn/internal.js +2 -1
  133. package/dist/rn/internal.js.map +1 -1
  134. package/dist/rn/{phone-22e871c4.js → phone-7f3181c6.js} +681 -239
  135. package/dist/rn/phone-7f3181c6.js.map +1 -0
  136. package/dist/rn/src/api/authentication/email_and_password.d.ts +9 -0
  137. package/dist/rn/src/api/authentication/recaptcha.d.ts +16 -0
  138. package/dist/rn/src/api/authentication/sign_up.d.ts +4 -0
  139. package/dist/rn/src/api/errors.d.ts +9 -1
  140. package/dist/rn/src/api/index.d.ts +15 -1
  141. package/dist/rn/src/core/auth/auth_impl.d.ts +5 -0
  142. package/dist/rn/src/core/errors.d.ts +17 -1
  143. package/dist/rn/src/core/index.d.ts +26 -0
  144. package/dist/rn/src/model/auth.d.ts +5 -0
  145. package/dist/rn/src/platform_browser/auth_window.d.ts +2 -2
  146. package/dist/rn/src/platform_browser/recaptcha/recaptcha.d.ts +33 -0
  147. package/dist/rn/src/platform_browser/recaptcha/recaptcha.test.d.ts +17 -0
  148. package/dist/rn/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +40 -0
  149. package/dist/rn/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.test.d.ts +17 -0
  150. package/dist/rn/src/platform_browser/recaptcha/recaptcha_mock.d.ts +16 -1
  151. package/dist/rn/test/helpers/api/helper.d.ts +2 -0
  152. package/dist/src/api/authentication/email_and_password.d.ts +9 -0
  153. package/dist/src/api/authentication/recaptcha.d.ts +16 -0
  154. package/dist/src/api/authentication/sign_up.d.ts +4 -0
  155. package/dist/src/api/errors.d.ts +9 -1
  156. package/dist/src/api/index.d.ts +15 -1
  157. package/dist/src/core/auth/auth_impl.d.ts +5 -0
  158. package/dist/src/core/errors.d.ts +17 -1
  159. package/dist/src/core/index.d.ts +26 -0
  160. package/dist/src/model/auth.d.ts +5 -0
  161. package/dist/src/platform_browser/auth_window.d.ts +2 -2
  162. package/dist/src/platform_browser/recaptcha/recaptcha.d.ts +33 -0
  163. package/dist/src/platform_browser/recaptcha/recaptcha.test.d.ts +17 -0
  164. package/dist/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +40 -0
  165. package/dist/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.test.d.ts +17 -0
  166. package/dist/src/platform_browser/recaptcha/recaptcha_mock.d.ts +16 -1
  167. package/dist/test/helpers/api/helper.d.ts +2 -0
  168. package/package.json +6 -6
  169. package/dist/browser-cjs/index-f15d4bca.js.map +0 -1
  170. package/dist/cordova/popup_redirect-6a7ae974.js.map +0 -1
  171. package/dist/esm2017/index-73d232c4.js.map +0 -1
  172. package/dist/esm5/index-612b0526.js.map +0 -1
  173. package/dist/node/totp-84316976.js.map +0 -1
  174. package/dist/node-esm/totp-0e6e00b2.js.map +0 -1
  175. package/dist/rn/phone-22e871c4.js.map +0 -1
@@ -2,8 +2,8 @@
2
2
 
3
3
  var util = require('@firebase/util');
4
4
  var app = require('@firebase/app');
5
- var logger = require('@firebase/logger');
6
5
  var tslib = require('tslib');
6
+ var logger = require('@firebase/logger');
7
7
  var component = require('@firebase/component');
8
8
 
9
9
  /**
@@ -267,7 +267,15 @@ function _debugErrorMap() {
267
267
  ["already-initialized" /* AuthErrorCode.ALREADY_INITIALIZED */]: 'initializeAuth() has already been called with ' +
268
268
  'different options. To avoid this error, call initializeAuth() with the ' +
269
269
  'same options as when it was originally called, or call getAuth() to return the' +
270
- ' already initialized instance.'
270
+ ' already initialized instance.',
271
+ ["missing-recaptcha-token" /* AuthErrorCode.MISSING_RECAPTCHA_TOKEN */]: 'The reCAPTCHA token is missing when sending request to the backend.',
272
+ ["invalid-recaptcha-token" /* AuthErrorCode.INVALID_RECAPTCHA_TOKEN */]: 'The reCAPTCHA token is invalid when sending request to the backend.',
273
+ ["invalid-recaptcha-action" /* AuthErrorCode.INVALID_RECAPTCHA_ACTION */]: 'The reCAPTCHA action is invalid when sending request to the backend.',
274
+ ["recaptcha-not-enabled" /* AuthErrorCode.RECAPTCHA_NOT_ENABLED */]: 'reCAPTCHA Enterprise integration is not enabled for this project.',
275
+ ["missing-client-type" /* AuthErrorCode.MISSING_CLIENT_TYPE */]: 'The reCAPTCHA client type is missing when sending request to the backend.',
276
+ ["missing-recaptcha-version" /* AuthErrorCode.MISSING_RECAPTCHA_VERSION */]: 'The reCAPTCHA version is missing when sending request to the backend.',
277
+ ["invalid-req-type" /* AuthErrorCode.INVALID_REQ_TYPE */]: 'Invalid request parameters.',
278
+ ["invalid-recaptcha-version" /* AuthErrorCode.INVALID_RECAPTCHA_VERSION */]: 'The reCAPTCHA version is invalid when sending request to the backend.'
271
279
  };
272
280
  }
273
281
  function _prodErrorMap() {
@@ -403,7 +411,15 @@ const AUTH_ERROR_CODES_MAP_DO_NOT_USE_INTERNALLY = {
403
411
  USER_SIGNED_OUT: 'auth/user-signed-out',
404
412
  WEAK_PASSWORD: 'auth/weak-password',
405
413
  WEB_STORAGE_UNSUPPORTED: 'auth/web-storage-unsupported',
406
- ALREADY_INITIALIZED: 'auth/already-initialized'
414
+ ALREADY_INITIALIZED: 'auth/already-initialized',
415
+ RECAPTCHA_NOT_ENABLED: 'auth/recaptcha-not-enabled',
416
+ MISSING_RECAPTCHA_TOKEN: 'auth/missing-recaptcha-token',
417
+ INVALID_RECAPTCHA_TOKEN: 'auth/invalid-recaptcha-token',
418
+ INVALID_RECAPTCHA_ACTION: 'auth/invalid-recaptcha-action',
419
+ MISSING_CLIENT_TYPE: 'auth/missing-client-type',
420
+ MISSING_RECAPTCHA_VERSION: 'auth/missing-recaptcha-version',
421
+ INVALID_RECAPTCHA_VERSION: 'auth/invalid-recaptcha-version',
422
+ INVALID_REQ_TYPE: 'auth/invalid-req-type'
407
423
  };
408
424
 
409
425
  /**
@@ -518,103 +534,6 @@ function debugAssert(assertion, message) {
518
534
  }
519
535
  }
520
536
 
521
- /**
522
- * @license
523
- * Copyright 2020 Google LLC
524
- *
525
- * Licensed under the Apache License, Version 2.0 (the "License");
526
- * you may not use this file except in compliance with the License.
527
- * You may obtain a copy of the License at
528
- *
529
- * http://www.apache.org/licenses/LICENSE-2.0
530
- *
531
- * Unless required by applicable law or agreed to in writing, software
532
- * distributed under the License is distributed on an "AS IS" BASIS,
533
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
534
- * See the License for the specific language governing permissions and
535
- * limitations under the License.
536
- */
537
- const instanceCache = new Map();
538
- function _getInstance(cls) {
539
- debugAssert(cls instanceof Function, 'Expected a class definition');
540
- let instance = instanceCache.get(cls);
541
- if (instance) {
542
- debugAssert(instance instanceof cls, 'Instance stored in cache mismatched with class');
543
- return instance;
544
- }
545
- instance = new cls();
546
- instanceCache.set(cls, instance);
547
- return instance;
548
- }
549
-
550
- /**
551
- * @license
552
- * Copyright 2020 Google LLC
553
- *
554
- * Licensed under the Apache License, Version 2.0 (the "License");
555
- * you may not use this file except in compliance with the License.
556
- * You may obtain a copy of the License at
557
- *
558
- * http://www.apache.org/licenses/LICENSE-2.0
559
- *
560
- * Unless required by applicable law or agreed to in writing, software
561
- * distributed under the License is distributed on an "AS IS" BASIS,
562
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
563
- * See the License for the specific language governing permissions and
564
- * limitations under the License.
565
- */
566
- /**
567
- * Initializes an {@link Auth} instance with fine-grained control over
568
- * {@link Dependencies}.
569
- *
570
- * @remarks
571
- *
572
- * This function allows more control over the {@link Auth} instance than
573
- * {@link getAuth}. `getAuth` uses platform-specific defaults to supply
574
- * the {@link Dependencies}. In general, `getAuth` is the easiest way to
575
- * initialize Auth and works for most use cases. Use `initializeAuth` if you
576
- * need control over which persistence layer is used, or to minimize bundle
577
- * size if you're not using either `signInWithPopup` or `signInWithRedirect`.
578
- *
579
- * For example, if your app only uses anonymous accounts and you only want
580
- * accounts saved for the current session, initialize `Auth` with:
581
- *
582
- * ```js
583
- * const auth = initializeAuth(app, {
584
- * persistence: browserSessionPersistence,
585
- * popupRedirectResolver: undefined,
586
- * });
587
- * ```
588
- *
589
- * @public
590
- */
591
- function initializeAuth(app$1, deps) {
592
- const provider = app._getProvider(app$1, 'auth');
593
- if (provider.isInitialized()) {
594
- const auth = provider.getImmediate();
595
- const initialOptions = provider.getOptions();
596
- if (util.deepEqual(initialOptions, deps !== null && deps !== void 0 ? deps : {})) {
597
- return auth;
598
- }
599
- else {
600
- _fail(auth, "already-initialized" /* AuthErrorCode.ALREADY_INITIALIZED */);
601
- }
602
- }
603
- const auth = provider.initialize({ options: deps });
604
- return auth;
605
- }
606
- function _initializeAuthInstance(auth, deps) {
607
- const persistence = (deps === null || deps === void 0 ? void 0 : deps.persistence) || [];
608
- const hierarchy = (Array.isArray(persistence) ? persistence : [persistence]).map(_getInstance);
609
- if (deps === null || deps === void 0 ? void 0 : deps.errorMap) {
610
- auth._updateErrorMap(deps.errorMap);
611
- }
612
- // This promise is intended to float; auth initialization happens in the
613
- // background, meanwhile the auth object may be used by the app.
614
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
615
- auth._initializeWithPersistence(hierarchy, deps === null || deps === void 0 ? void 0 : deps.popupRedirectResolver);
616
- }
617
-
618
537
  /**
619
538
  * @license
620
539
  * Copyright 2020 Google LLC
@@ -893,7 +812,16 @@ const SERVER_ERROR_MAP = {
893
812
  ["SECOND_FACTOR_EXISTS" /* ServerError.SECOND_FACTOR_EXISTS */]: "second-factor-already-in-use" /* AuthErrorCode.SECOND_FACTOR_ALREADY_ENROLLED */,
894
813
  ["SECOND_FACTOR_LIMIT_EXCEEDED" /* ServerError.SECOND_FACTOR_LIMIT_EXCEEDED */]: "maximum-second-factor-count-exceeded" /* AuthErrorCode.SECOND_FACTOR_LIMIT_EXCEEDED */,
895
814
  // Blocking functions related errors.
896
- ["BLOCKING_FUNCTION_ERROR_RESPONSE" /* ServerError.BLOCKING_FUNCTION_ERROR_RESPONSE */]: "internal-error" /* AuthErrorCode.INTERNAL_ERROR */
815
+ ["BLOCKING_FUNCTION_ERROR_RESPONSE" /* ServerError.BLOCKING_FUNCTION_ERROR_RESPONSE */]: "internal-error" /* AuthErrorCode.INTERNAL_ERROR */,
816
+ // Recaptcha related errors.
817
+ ["RECAPTCHA_NOT_ENABLED" /* ServerError.RECAPTCHA_NOT_ENABLED */]: "recaptcha-not-enabled" /* AuthErrorCode.RECAPTCHA_NOT_ENABLED */,
818
+ ["MISSING_RECAPTCHA_TOKEN" /* ServerError.MISSING_RECAPTCHA_TOKEN */]: "missing-recaptcha-token" /* AuthErrorCode.MISSING_RECAPTCHA_TOKEN */,
819
+ ["INVALID_RECAPTCHA_TOKEN" /* ServerError.INVALID_RECAPTCHA_TOKEN */]: "invalid-recaptcha-token" /* AuthErrorCode.INVALID_RECAPTCHA_TOKEN */,
820
+ ["INVALID_RECAPTCHA_ACTION" /* ServerError.INVALID_RECAPTCHA_ACTION */]: "invalid-recaptcha-action" /* AuthErrorCode.INVALID_RECAPTCHA_ACTION */,
821
+ ["MISSING_CLIENT_TYPE" /* ServerError.MISSING_CLIENT_TYPE */]: "missing-client-type" /* AuthErrorCode.MISSING_CLIENT_TYPE */,
822
+ ["MISSING_RECAPTCHA_VERSION" /* ServerError.MISSING_RECAPTCHA_VERSION */]: "missing-recaptcha-version" /* AuthErrorCode.MISSING_RECAPTCHA_VERSION */,
823
+ ["INVALID_RECAPTCHA_VERSION" /* ServerError.INVALID_RECAPTCHA_VERSION */]: "invalid-recaptcha-version" /* AuthErrorCode.INVALID_RECAPTCHA_VERSION */,
824
+ ["INVALID_REQ_TYPE" /* ServerError.INVALID_REQ_TYPE */]: "invalid-req-type" /* AuthErrorCode.INVALID_REQ_TYPE */
897
825
  };
898
826
 
899
827
  /**
@@ -1795,6 +1723,35 @@ class UserImpl {
1795
1723
  }
1796
1724
  }
1797
1725
 
1726
+ /**
1727
+ * @license
1728
+ * Copyright 2020 Google LLC
1729
+ *
1730
+ * Licensed under the Apache License, Version 2.0 (the "License");
1731
+ * you may not use this file except in compliance with the License.
1732
+ * You may obtain a copy of the License at
1733
+ *
1734
+ * http://www.apache.org/licenses/LICENSE-2.0
1735
+ *
1736
+ * Unless required by applicable law or agreed to in writing, software
1737
+ * distributed under the License is distributed on an "AS IS" BASIS,
1738
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1739
+ * See the License for the specific language governing permissions and
1740
+ * limitations under the License.
1741
+ */
1742
+ const instanceCache = new Map();
1743
+ function _getInstance(cls) {
1744
+ debugAssert(cls instanceof Function, 'Expected a class definition');
1745
+ let instance = instanceCache.get(cls);
1746
+ if (instance) {
1747
+ debugAssert(instance instanceof cls, 'Instance stored in cache mismatched with class');
1748
+ return instance;
1749
+ }
1750
+ instance = new cls();
1751
+ instanceCache.set(cls, instance);
1752
+ return instance;
1753
+ }
1754
+
1798
1755
  /**
1799
1756
  * @license
1800
1757
  * Copyright 2019 Google LLC
@@ -2136,6 +2093,242 @@ function _getClientVersion(clientPlatform, frameworks = []) {
2136
2093
  return `${reportedPlatform}/${"JsCore" /* ClientImplementation.CORE */}/${app.SDK_VERSION}/${reportedFrameworks}`;
2137
2094
  }
2138
2095
 
2096
+ /**
2097
+ * @license
2098
+ * Copyright 2020 Google LLC
2099
+ *
2100
+ * Licensed under the Apache License, Version 2.0 (the "License");
2101
+ * you may not use this file except in compliance with the License.
2102
+ * You may obtain a copy of the License at
2103
+ *
2104
+ * http://www.apache.org/licenses/LICENSE-2.0
2105
+ *
2106
+ * Unless required by applicable law or agreed to in writing, software
2107
+ * distributed under the License is distributed on an "AS IS" BASIS,
2108
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2109
+ * See the License for the specific language governing permissions and
2110
+ * limitations under the License.
2111
+ */
2112
+ async function getRecaptchaParams(auth) {
2113
+ return ((await _performApiRequest(auth, "GET" /* HttpMethod.GET */, "/v1/recaptchaParams" /* Endpoint.GET_RECAPTCHA_PARAM */)).recaptchaSiteKey || '');
2114
+ }
2115
+ async function getRecaptchaConfig(auth, request) {
2116
+ return _performApiRequest(auth, "GET" /* HttpMethod.GET */, "/v2/recaptchaConfig" /* Endpoint.GET_RECAPTCHA_CONFIG */, _addTidIfNecessary(auth, request));
2117
+ }
2118
+
2119
+ /**
2120
+ * @license
2121
+ * Copyright 2020 Google LLC
2122
+ *
2123
+ * Licensed under the Apache License, Version 2.0 (the "License");
2124
+ * you may not use this file except in compliance with the License.
2125
+ * You may obtain a copy of the License at
2126
+ *
2127
+ * http://www.apache.org/licenses/LICENSE-2.0
2128
+ *
2129
+ * Unless required by applicable law or agreed to in writing, software
2130
+ * distributed under the License is distributed on an "AS IS" BASIS,
2131
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2132
+ * See the License for the specific language governing permissions and
2133
+ * limitations under the License.
2134
+ */
2135
+ function isV2(grecaptcha) {
2136
+ return (grecaptcha !== undefined &&
2137
+ grecaptcha.getResponse !== undefined);
2138
+ }
2139
+ function isEnterprise(grecaptcha) {
2140
+ return (grecaptcha !== undefined &&
2141
+ grecaptcha.enterprise !== undefined);
2142
+ }
2143
+ class RecaptchaConfig {
2144
+ constructor(response) {
2145
+ /**
2146
+ * The reCAPTCHA site key.
2147
+ */
2148
+ this.siteKey = '';
2149
+ /**
2150
+ * The reCAPTCHA enablement status of the {@link EmailAuthProvider} for the current tenant.
2151
+ */
2152
+ this.emailPasswordEnabled = false;
2153
+ if (response.recaptchaKey === undefined) {
2154
+ throw new Error('recaptchaKey undefined');
2155
+ }
2156
+ // Example response.recaptchaKey: "projects/proj123/keys/sitekey123"
2157
+ this.siteKey = response.recaptchaKey.split('/')[3];
2158
+ this.emailPasswordEnabled = response.recaptchaEnforcementState.some(enforcementState => enforcementState.provider === 'EMAIL_PASSWORD_PROVIDER' &&
2159
+ enforcementState.enforcementState !== 'OFF');
2160
+ }
2161
+ }
2162
+
2163
+ /**
2164
+ * @license
2165
+ * Copyright 2020 Google LLC
2166
+ *
2167
+ * Licensed under the Apache License, Version 2.0 (the "License");
2168
+ * you may not use this file except in compliance with the License.
2169
+ * You may obtain a copy of the License at
2170
+ *
2171
+ * http://www.apache.org/licenses/LICENSE-2.0
2172
+ *
2173
+ * Unless required by applicable law or agreed to in writing, software
2174
+ * distributed under the License is distributed on an "AS IS" BASIS,
2175
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2176
+ * See the License for the specific language governing permissions and
2177
+ * limitations under the License.
2178
+ */
2179
+ function getScriptParentElement() {
2180
+ var _a, _b;
2181
+ return (_b = (_a = document.getElementsByTagName('head')) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : document;
2182
+ }
2183
+ function _loadJS(url) {
2184
+ // TODO: consider adding timeout support & cancellation
2185
+ return new Promise((resolve, reject) => {
2186
+ const el = document.createElement('script');
2187
+ el.setAttribute('src', url);
2188
+ el.onload = resolve;
2189
+ el.onerror = e => {
2190
+ const error = _createError("internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
2191
+ error.customData = e;
2192
+ reject(error);
2193
+ };
2194
+ el.type = 'text/javascript';
2195
+ el.charset = 'UTF-8';
2196
+ getScriptParentElement().appendChild(el);
2197
+ });
2198
+ }
2199
+ function _generateCallbackName(prefix) {
2200
+ return `__${prefix}${Math.floor(Math.random() * 1000000)}`;
2201
+ }
2202
+
2203
+ /* eslint-disable @typescript-eslint/no-require-imports */
2204
+ const RECAPTCHA_ENTERPRISE_URL = 'https://www.google.com/recaptcha/enterprise.js?render=';
2205
+ const RECAPTCHA_ENTERPRISE_VERIFIER_TYPE = 'recaptcha-enterprise';
2206
+ class RecaptchaEnterpriseVerifier {
2207
+ /**
2208
+ *
2209
+ * @param authExtern - The corresponding Firebase {@link Auth} instance.
2210
+ *
2211
+ */
2212
+ constructor(authExtern) {
2213
+ /**
2214
+ * Identifies the type of application verifier (e.g. "recaptcha-enterprise").
2215
+ */
2216
+ this.type = RECAPTCHA_ENTERPRISE_VERIFIER_TYPE;
2217
+ this.auth = _castAuth(authExtern);
2218
+ }
2219
+ /**
2220
+ * Executes the verification process.
2221
+ *
2222
+ * @returns A Promise for a token that can be used to assert the validity of a request.
2223
+ */
2224
+ async verify(action = 'verify', forceRefresh = false) {
2225
+ async function retrieveSiteKey(auth) {
2226
+ if (!forceRefresh) {
2227
+ if (auth.tenantId == null && auth._agentRecaptchaConfig != null) {
2228
+ return auth._agentRecaptchaConfig.siteKey;
2229
+ }
2230
+ if (auth.tenantId != null &&
2231
+ auth._tenantRecaptchaConfigs[auth.tenantId] !== undefined) {
2232
+ return auth._tenantRecaptchaConfigs[auth.tenantId].siteKey;
2233
+ }
2234
+ }
2235
+ return new Promise(async (resolve, reject) => {
2236
+ getRecaptchaConfig(auth, {
2237
+ clientType: "CLIENT_TYPE_WEB" /* RecaptchaClientType.WEB */,
2238
+ version: "RECAPTCHA_ENTERPRISE" /* RecaptchaVersion.ENTERPRISE */
2239
+ })
2240
+ .then(response => {
2241
+ if (response.recaptchaKey === undefined) {
2242
+ reject(new Error('recaptcha Enterprise site key undefined'));
2243
+ }
2244
+ else {
2245
+ const config = new RecaptchaConfig(response);
2246
+ if (auth.tenantId == null) {
2247
+ auth._agentRecaptchaConfig = config;
2248
+ }
2249
+ else {
2250
+ auth._tenantRecaptchaConfigs[auth.tenantId] = config;
2251
+ }
2252
+ return resolve(config.siteKey);
2253
+ }
2254
+ })
2255
+ .catch(error => {
2256
+ reject(error);
2257
+ });
2258
+ });
2259
+ }
2260
+ function retrieveRecaptchaToken(siteKey, resolve, reject) {
2261
+ const grecaptcha = window.grecaptcha;
2262
+ if (isEnterprise(grecaptcha)) {
2263
+ grecaptcha.enterprise.ready(() => {
2264
+ try {
2265
+ grecaptcha.enterprise
2266
+ .execute(siteKey, { action })
2267
+ .then(token => {
2268
+ resolve(token);
2269
+ })
2270
+ .catch(error => {
2271
+ reject(error);
2272
+ });
2273
+ }
2274
+ catch (error) {
2275
+ reject(error);
2276
+ }
2277
+ });
2278
+ }
2279
+ else {
2280
+ reject(Error('No reCAPTCHA enterprise script loaded.'));
2281
+ }
2282
+ }
2283
+ return new Promise((resolve, reject) => {
2284
+ retrieveSiteKey(this.auth)
2285
+ .then(siteKey => {
2286
+ if (!forceRefresh && isEnterprise(window.grecaptcha)) {
2287
+ retrieveRecaptchaToken(siteKey, resolve, reject);
2288
+ }
2289
+ else {
2290
+ if (typeof window === 'undefined') {
2291
+ reject(new Error('RecaptchaVerifier is only supported in browser'));
2292
+ return;
2293
+ }
2294
+ _loadJS(RECAPTCHA_ENTERPRISE_URL + siteKey)
2295
+ .then(() => {
2296
+ retrieveRecaptchaToken(siteKey, resolve, reject);
2297
+ })
2298
+ .catch(error => {
2299
+ reject(error);
2300
+ });
2301
+ }
2302
+ })
2303
+ .catch(error => {
2304
+ reject(error);
2305
+ });
2306
+ });
2307
+ }
2308
+ }
2309
+ async function injectRecaptchaFields(auth, request, action, captchaResp = false) {
2310
+ const verifier = new RecaptchaEnterpriseVerifier(auth);
2311
+ let captchaResponse;
2312
+ try {
2313
+ captchaResponse = await verifier.verify(action);
2314
+ }
2315
+ catch (error) {
2316
+ captchaResponse = await verifier.verify(action, true);
2317
+ }
2318
+ const newRequest = Object.assign({}, request);
2319
+ if (!captchaResp) {
2320
+ Object.assign(newRequest, { captchaResponse });
2321
+ }
2322
+ else {
2323
+ Object.assign(newRequest, { 'captchaResp': captchaResponse });
2324
+ }
2325
+ Object.assign(newRequest, { 'clientType': "CLIENT_TYPE_WEB" /* RecaptchaClientType.WEB */ });
2326
+ Object.assign(newRequest, {
2327
+ 'recaptchaVersion': "RECAPTCHA_ENTERPRISE" /* RecaptchaVersion.ENTERPRISE */
2328
+ });
2329
+ return newRequest;
2330
+ }
2331
+
2139
2332
  /**
2140
2333
  * @license
2141
2334
  * Copyright 2022 Google LLC
@@ -2255,6 +2448,8 @@ class AuthImpl {
2255
2448
  this._initializationPromise = null;
2256
2449
  this._popupRedirectResolver = null;
2257
2450
  this._errorFactory = _DEFAULT_AUTH_ERROR_FACTORY;
2451
+ this._agentRecaptchaConfig = null;
2452
+ this._tenantRecaptchaConfigs = {};
2258
2453
  // Tracks the last notified UID for state change listeners to prevent
2259
2454
  // repeated calls to the callbacks. Undefined means it's never been
2260
2455
  // called, whereas null means it's been called with a signed out user
@@ -2474,6 +2669,31 @@ class AuthImpl {
2474
2669
  await this.assertedPersistence.setPersistence(_getInstance(persistence));
2475
2670
  });
2476
2671
  }
2672
+ async initializeRecaptchaConfig() {
2673
+ const response = await getRecaptchaConfig(this, {
2674
+ clientType: "CLIENT_TYPE_WEB" /* RecaptchaClientType.WEB */,
2675
+ version: "RECAPTCHA_ENTERPRISE" /* RecaptchaVersion.ENTERPRISE */
2676
+ });
2677
+ const config = new RecaptchaConfig(response);
2678
+ if (this.tenantId == null) {
2679
+ this._agentRecaptchaConfig = config;
2680
+ }
2681
+ else {
2682
+ this._tenantRecaptchaConfigs[this.tenantId] = config;
2683
+ }
2684
+ if (config.emailPasswordEnabled) {
2685
+ const verifier = new RecaptchaEnterpriseVerifier(this);
2686
+ void verifier.verify();
2687
+ }
2688
+ }
2689
+ _getRecaptchaConfig() {
2690
+ if (this.tenantId == null) {
2691
+ return this._agentRecaptchaConfig;
2692
+ }
2693
+ else {
2694
+ return this._tenantRecaptchaConfigs[this.tenantId];
2695
+ }
2696
+ }
2477
2697
  _getPersistence() {
2478
2698
  return this.assertedPersistence.persistence.type;
2479
2699
  }
@@ -2696,6 +2916,74 @@ class Subscription {
2696
2916
  }
2697
2917
  }
2698
2918
 
2919
+ /**
2920
+ * @license
2921
+ * Copyright 2020 Google LLC
2922
+ *
2923
+ * Licensed under the Apache License, Version 2.0 (the "License");
2924
+ * you may not use this file except in compliance with the License.
2925
+ * You may obtain a copy of the License at
2926
+ *
2927
+ * http://www.apache.org/licenses/LICENSE-2.0
2928
+ *
2929
+ * Unless required by applicable law or agreed to in writing, software
2930
+ * distributed under the License is distributed on an "AS IS" BASIS,
2931
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2932
+ * See the License for the specific language governing permissions and
2933
+ * limitations under the License.
2934
+ */
2935
+ /**
2936
+ * Initializes an {@link Auth} instance with fine-grained control over
2937
+ * {@link Dependencies}.
2938
+ *
2939
+ * @remarks
2940
+ *
2941
+ * This function allows more control over the {@link Auth} instance than
2942
+ * {@link getAuth}. `getAuth` uses platform-specific defaults to supply
2943
+ * the {@link Dependencies}. In general, `getAuth` is the easiest way to
2944
+ * initialize Auth and works for most use cases. Use `initializeAuth` if you
2945
+ * need control over which persistence layer is used, or to minimize bundle
2946
+ * size if you're not using either `signInWithPopup` or `signInWithRedirect`.
2947
+ *
2948
+ * For example, if your app only uses anonymous accounts and you only want
2949
+ * accounts saved for the current session, initialize `Auth` with:
2950
+ *
2951
+ * ```js
2952
+ * const auth = initializeAuth(app, {
2953
+ * persistence: browserSessionPersistence,
2954
+ * popupRedirectResolver: undefined,
2955
+ * });
2956
+ * ```
2957
+ *
2958
+ * @public
2959
+ */
2960
+ function initializeAuth(app$1, deps) {
2961
+ const provider = app._getProvider(app$1, 'auth');
2962
+ if (provider.isInitialized()) {
2963
+ const auth = provider.getImmediate();
2964
+ const initialOptions = provider.getOptions();
2965
+ if (util.deepEqual(initialOptions, deps !== null && deps !== void 0 ? deps : {})) {
2966
+ return auth;
2967
+ }
2968
+ else {
2969
+ _fail(auth, "already-initialized" /* AuthErrorCode.ALREADY_INITIALIZED */);
2970
+ }
2971
+ }
2972
+ const auth = provider.initialize({ options: deps });
2973
+ return auth;
2974
+ }
2975
+ function _initializeAuthInstance(auth, deps) {
2976
+ const persistence = (deps === null || deps === void 0 ? void 0 : deps.persistence) || [];
2977
+ const hierarchy = (Array.isArray(persistence) ? persistence : [persistence]).map(_getInstance);
2978
+ if (deps === null || deps === void 0 ? void 0 : deps.errorMap) {
2979
+ auth._updateErrorMap(deps.errorMap);
2980
+ }
2981
+ // This promise is intended to float; auth initialization happens in the
2982
+ // background, meanwhile the auth object may be used by the app.
2983
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
2984
+ auth._initializeWithPersistence(hierarchy, deps === null || deps === void 0 ? void 0 : deps.popupRedirectResolver);
2985
+ }
2986
+
2699
2987
  /**
2700
2988
  * Changes the {@link Auth} instance to communicate with the Firebase Auth Emulator, instead of production
2701
2989
  * Firebase Auth services.
@@ -3035,13 +3323,31 @@ class EmailAuthCredential extends AuthCredential {
3035
3323
  }
3036
3324
  /** @internal */
3037
3325
  async _getIdTokenResponse(auth) {
3326
+ var _a;
3038
3327
  switch (this.signInMethod) {
3039
3328
  case "password" /* SignInMethod.EMAIL_PASSWORD */:
3040
- return signInWithPassword(auth, {
3329
+ const request = {
3041
3330
  returnSecureToken: true,
3042
3331
  email: this._email,
3043
- password: this._password
3044
- });
3332
+ password: this._password,
3333
+ clientType: "CLIENT_TYPE_WEB" /* RecaptchaClientType.WEB */
3334
+ };
3335
+ if ((_a = auth._getRecaptchaConfig()) === null || _a === void 0 ? void 0 : _a.emailPasswordEnabled) {
3336
+ const requestWithRecaptcha = await injectRecaptchaFields(auth, request, "signInWithPassword" /* RecaptchaActionName.SIGN_IN_WITH_PASSWORD */);
3337
+ return signInWithPassword(auth, requestWithRecaptcha);
3338
+ }
3339
+ else {
3340
+ return signInWithPassword(auth, request).catch(async (error) => {
3341
+ if (error.code === `auth/${"missing-recaptcha-token" /* AuthErrorCode.MISSING_RECAPTCHA_TOKEN */}`) {
3342
+ 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.');
3343
+ const requestWithRecaptcha = await injectRecaptchaFields(auth, request, "signInWithPassword" /* RecaptchaActionName.SIGN_IN_WITH_PASSWORD */);
3344
+ return signInWithPassword(auth, requestWithRecaptcha);
3345
+ }
3346
+ else {
3347
+ return Promise.reject(error);
3348
+ }
3349
+ });
3350
+ }
3045
3351
  case "emailLink" /* SignInMethod.EMAIL_LINK */:
3046
3352
  return signInWithEmailLink$1(auth, {
3047
3353
  email: this._email,
@@ -5000,15 +5306,39 @@ function _setActionCodeSettingsOnRequest(auth, request, actionCodeSettings) {
5000
5306
  * @public
5001
5307
  */
5002
5308
  async function sendPasswordResetEmail(auth, email, actionCodeSettings) {
5003
- const authModular = util.getModularInstance(auth);
5309
+ var _a;
5310
+ const authInternal = _castAuth(auth);
5004
5311
  const request = {
5005
5312
  requestType: "PASSWORD_RESET" /* ActionCodeOperation.PASSWORD_RESET */,
5006
- email
5313
+ email,
5314
+ clientType: "CLIENT_TYPE_WEB" /* RecaptchaClientType.WEB */
5007
5315
  };
5008
- if (actionCodeSettings) {
5009
- _setActionCodeSettingsOnRequest(authModular, request, actionCodeSettings);
5316
+ if ((_a = authInternal._getRecaptchaConfig()) === null || _a === void 0 ? void 0 : _a.emailPasswordEnabled) {
5317
+ const requestWithRecaptcha = await injectRecaptchaFields(authInternal, request, "getOobCode" /* RecaptchaActionName.GET_OOB_CODE */, true);
5318
+ if (actionCodeSettings) {
5319
+ _setActionCodeSettingsOnRequest(authInternal, requestWithRecaptcha, actionCodeSettings);
5320
+ }
5321
+ await sendPasswordResetEmail$1(authInternal, requestWithRecaptcha);
5322
+ }
5323
+ else {
5324
+ if (actionCodeSettings) {
5325
+ _setActionCodeSettingsOnRequest(authInternal, request, actionCodeSettings);
5326
+ }
5327
+ await sendPasswordResetEmail$1(authInternal, request)
5328
+ .catch(async (error) => {
5329
+ if (error.code === `auth/${"missing-recaptcha-token" /* AuthErrorCode.MISSING_RECAPTCHA_TOKEN */}`) {
5330
+ console.log('Password resets are protected by reCAPTCHA for this project. Automatically triggering the reCAPTCHA flow and restarting the password reset flow.');
5331
+ const requestWithRecaptcha = await injectRecaptchaFields(authInternal, request, "getOobCode" /* RecaptchaActionName.GET_OOB_CODE */, true);
5332
+ if (actionCodeSettings) {
5333
+ _setActionCodeSettingsOnRequest(authInternal, requestWithRecaptcha, actionCodeSettings);
5334
+ }
5335
+ await sendPasswordResetEmail$1(authInternal, requestWithRecaptcha);
5336
+ }
5337
+ else {
5338
+ return Promise.reject(error);
5339
+ }
5340
+ });
5010
5341
  }
5011
- await sendPasswordResetEmail$1(authModular, request);
5012
5342
  }
5013
5343
  /**
5014
5344
  * Completes the password reset process, given a confirmation code and new password.
@@ -5121,11 +5451,33 @@ async function verifyPasswordResetCode(auth, code) {
5121
5451
  * @public
5122
5452
  */
5123
5453
  async function createUserWithEmailAndPassword(auth, email, password) {
5454
+ var _a;
5124
5455
  const authInternal = _castAuth(auth);
5125
- const response = await signUp(authInternal, {
5456
+ const request = {
5126
5457
  returnSecureToken: true,
5127
5458
  email,
5128
- password
5459
+ password,
5460
+ clientType: "CLIENT_TYPE_WEB" /* RecaptchaClientType.WEB */
5461
+ };
5462
+ let signUpResponse;
5463
+ if ((_a = authInternal._getRecaptchaConfig()) === null || _a === void 0 ? void 0 : _a.emailPasswordEnabled) {
5464
+ const requestWithRecaptcha = await injectRecaptchaFields(authInternal, request, "signUpPassword" /* RecaptchaActionName.SIGN_UP_PASSWORD */);
5465
+ signUpResponse = signUp(authInternal, requestWithRecaptcha);
5466
+ }
5467
+ else {
5468
+ signUpResponse = signUp(authInternal, request).catch(async (error) => {
5469
+ if (error.code === `auth/${"missing-recaptcha-token" /* AuthErrorCode.MISSING_RECAPTCHA_TOKEN */}`) {
5470
+ console.log('Sign-up is protected by reCAPTCHA for this project. Automatically triggering the reCAPTCHA flow and restarting the sign-up flow.');
5471
+ const requestWithRecaptcha = await injectRecaptchaFields(authInternal, request, "signUpPassword" /* RecaptchaActionName.SIGN_UP_PASSWORD */);
5472
+ return signUp(authInternal, requestWithRecaptcha);
5473
+ }
5474
+ else {
5475
+ return Promise.reject(error);
5476
+ }
5477
+ });
5478
+ }
5479
+ const response = await signUpResponse.catch(error => {
5480
+ return Promise.reject(error);
5129
5481
  });
5130
5482
  const userCredential = await UserCredentialImpl._fromIdTokenResponse(authInternal, "signIn" /* OperationType.SIGN_IN */, response);
5131
5483
  await authInternal._updateCurrentUser(userCredential.user);
@@ -5206,16 +5558,39 @@ function signInWithEmailAndPassword(auth, email, password) {
5206
5558
  * @public
5207
5559
  */
5208
5560
  async function sendSignInLinkToEmail(auth, email, actionCodeSettings) {
5209
- const authModular = util.getModularInstance(auth);
5561
+ var _a;
5562
+ const authInternal = _castAuth(auth);
5210
5563
  const request = {
5211
5564
  requestType: "EMAIL_SIGNIN" /* ActionCodeOperation.EMAIL_SIGNIN */,
5212
- email
5565
+ email,
5566
+ clientType: "CLIENT_TYPE_WEB" /* RecaptchaClientType.WEB */
5213
5567
  };
5214
- _assert(actionCodeSettings.handleCodeInApp, authModular, "argument-error" /* AuthErrorCode.ARGUMENT_ERROR */);
5215
- if (actionCodeSettings) {
5216
- _setActionCodeSettingsOnRequest(authModular, request, actionCodeSettings);
5568
+ function setActionCodeSettings(request, actionCodeSettings) {
5569
+ _assert(actionCodeSettings.handleCodeInApp, authInternal, "argument-error" /* AuthErrorCode.ARGUMENT_ERROR */);
5570
+ if (actionCodeSettings) {
5571
+ _setActionCodeSettingsOnRequest(authInternal, request, actionCodeSettings);
5572
+ }
5573
+ }
5574
+ if ((_a = authInternal._getRecaptchaConfig()) === null || _a === void 0 ? void 0 : _a.emailPasswordEnabled) {
5575
+ const requestWithRecaptcha = await injectRecaptchaFields(authInternal, request, "getOobCode" /* RecaptchaActionName.GET_OOB_CODE */, true);
5576
+ setActionCodeSettings(requestWithRecaptcha, actionCodeSettings);
5577
+ await sendSignInLinkToEmail$1(authInternal, requestWithRecaptcha);
5578
+ }
5579
+ else {
5580
+ setActionCodeSettings(request, actionCodeSettings);
5581
+ await sendSignInLinkToEmail$1(authInternal, request)
5582
+ .catch(async (error) => {
5583
+ if (error.code === `auth/${"missing-recaptcha-token" /* AuthErrorCode.MISSING_RECAPTCHA_TOKEN */}`) {
5584
+ console.log('Email link sign-in is protected by reCAPTCHA for this project. Automatically triggering the reCAPTCHA flow and restarting the sign-in flow.');
5585
+ const requestWithRecaptcha = await injectRecaptchaFields(authInternal, request, "getOobCode" /* RecaptchaActionName.GET_OOB_CODE */, true);
5586
+ setActionCodeSettings(requestWithRecaptcha, actionCodeSettings);
5587
+ await sendSignInLinkToEmail$1(authInternal, requestWithRecaptcha);
5588
+ }
5589
+ else {
5590
+ return Promise.reject(error);
5591
+ }
5592
+ });
5217
5593
  }
5218
- await sendSignInLinkToEmail$1(authModular, request);
5219
5594
  }
5220
5595
  /**
5221
5596
  * Checks if an incoming link is a sign-in with email link suitable for {@link signInWithEmailLink}.
@@ -5710,6 +6085,35 @@ function getAdditionalUserInfo(userCredential) {
5710
6085
  function setPersistence(auth, persistence) {
5711
6086
  return util.getModularInstance(auth).setPersistence(persistence);
5712
6087
  }
6088
+ /**
6089
+ * Loads the reCAPTCHA configuration into the `Auth` instance.
6090
+ *
6091
+ * @remarks
6092
+ * This will load the reCAPTCHA config, which indicates whether the reCAPTCHA
6093
+ * verification flow should be triggered for each auth provider, into the
6094
+ * current Auth session.
6095
+ *
6096
+ * If initializeRecaptchaConfig() is not invoked, the auth flow will always start
6097
+ * without reCAPTCHA verification. If the provider is configured to require reCAPTCHA
6098
+ * verification, the SDK will transparently load the reCAPTCHA config and restart the
6099
+ * auth flows.
6100
+ *
6101
+ * Thus, by calling this optional method, you will reduce the latency of future auth flows.
6102
+ * Loading the reCAPTCHA config early will also enhance the signal collected by reCAPTCHA.
6103
+ *
6104
+ * @example
6105
+ * ```javascript
6106
+ * initializeRecaptchaConfig(auth);
6107
+ * ```
6108
+ *
6109
+ * @param auth - The {@link Auth} instance.
6110
+ *
6111
+ * @public
6112
+ */
6113
+ function initializeRecaptchaConfig(auth) {
6114
+ const authInternal = _castAuth(auth);
6115
+ return authInternal.initializeRecaptchaConfig();
6116
+ }
5713
6117
  /**
5714
6118
  * Adds an observer for changes to the signed-in user's ID token.
5715
6119
  *
@@ -7055,66 +7459,6 @@ function finalizeSignInTotpMfa(auth, request) {
7055
7459
  return _performApiRequest(auth, "POST" /* HttpMethod.POST */, "/v2/accounts/mfaSignIn:finalize" /* Endpoint.FINALIZE_MFA_SIGN_IN */, _addTidIfNecessary(auth, request));
7056
7460
  }
7057
7461
 
7058
- /**
7059
- * @license
7060
- * Copyright 2020 Google LLC
7061
- *
7062
- * Licensed under the Apache License, Version 2.0 (the "License");
7063
- * you may not use this file except in compliance with the License.
7064
- * You may obtain a copy of the License at
7065
- *
7066
- * http://www.apache.org/licenses/LICENSE-2.0
7067
- *
7068
- * Unless required by applicable law or agreed to in writing, software
7069
- * distributed under the License is distributed on an "AS IS" BASIS,
7070
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7071
- * See the License for the specific language governing permissions and
7072
- * limitations under the License.
7073
- */
7074
- async function getRecaptchaParams(auth) {
7075
- return ((await _performApiRequest(auth, "GET" /* HttpMethod.GET */, "/v1/recaptchaParams" /* Endpoint.GET_RECAPTCHA_PARAM */)).recaptchaSiteKey || '');
7076
- }
7077
-
7078
- /**
7079
- * @license
7080
- * Copyright 2020 Google LLC
7081
- *
7082
- * Licensed under the Apache License, Version 2.0 (the "License");
7083
- * you may not use this file except in compliance with the License.
7084
- * You may obtain a copy of the License at
7085
- *
7086
- * http://www.apache.org/licenses/LICENSE-2.0
7087
- *
7088
- * Unless required by applicable law or agreed to in writing, software
7089
- * distributed under the License is distributed on an "AS IS" BASIS,
7090
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7091
- * See the License for the specific language governing permissions and
7092
- * limitations under the License.
7093
- */
7094
- function getScriptParentElement() {
7095
- var _a, _b;
7096
- return (_b = (_a = document.getElementsByTagName('head')) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : document;
7097
- }
7098
- function _loadJS(url) {
7099
- // TODO: consider adding timeout support & cancellation
7100
- return new Promise((resolve, reject) => {
7101
- const el = document.createElement('script');
7102
- el.setAttribute('src', url);
7103
- el.onload = resolve;
7104
- el.onerror = e => {
7105
- const error = _createError("internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
7106
- error.customData = e;
7107
- reject(error);
7108
- };
7109
- el.type = 'text/javascript';
7110
- el.charset = 'UTF-8';
7111
- getScriptParentElement().appendChild(el);
7112
- });
7113
- }
7114
- function _generateCallbackName(prefix) {
7115
- return `__${prefix}${Math.floor(Math.random() * 1000000)}`;
7116
- }
7117
-
7118
7462
  /**
7119
7463
  * @license
7120
7464
  * Copyright 2020 Google LLC
@@ -7281,7 +7625,7 @@ class ReCaptchaLoaderImpl {
7281
7625
  }
7282
7626
  load(auth, hl = '') {
7283
7627
  _assert(isHostLanguageValid(hl), auth, "argument-error" /* AuthErrorCode.ARGUMENT_ERROR */);
7284
- if (this.shouldResolveImmediately(hl)) {
7628
+ if (this.shouldResolveImmediately(hl) && isV2(_window().grecaptcha)) {
7285
7629
  return Promise.resolve(_window().grecaptcha);
7286
7630
  }
7287
7631
  return new Promise((resolve, reject) => {
@@ -7292,7 +7636,7 @@ class ReCaptchaLoaderImpl {
7292
7636
  _window().clearTimeout(networkTimeout);
7293
7637
  delete _window()[_JSLOAD_CALLBACK];
7294
7638
  const recaptcha = _window().grecaptcha;
7295
- if (!recaptcha) {
7639
+ if (!recaptcha || !isV2(recaptcha)) {
7296
7640
  reject(_createError(auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */));
7297
7641
  return;
7298
7642
  }
@@ -9524,7 +9868,7 @@ function _isEmptyString(input) {
9524
9868
  }
9525
9869
 
9526
9870
  var name = "@firebase/auth";
9527
- var version = "0.22.0-canary.b66908df6";
9871
+ var version = "0.22.0-canary.ecb4454c3";
9528
9872
 
9529
9873
  /**
9530
9874
  * @license
@@ -9815,6 +10159,7 @@ exports.getRedirectResult = getRedirectResult;
9815
10159
  exports.inMemoryPersistence = inMemoryPersistence;
9816
10160
  exports.indexedDBLocalPersistence = indexedDBLocalPersistence;
9817
10161
  exports.initializeAuth = initializeAuth;
10162
+ exports.initializeRecaptchaConfig = initializeRecaptchaConfig;
9818
10163
  exports.isSignInWithEmailLink = isSignInWithEmailLink;
9819
10164
  exports.linkWithCredential = linkWithCredential;
9820
10165
  exports.linkWithPhoneNumber = linkWithPhoneNumber;
@@ -9852,4 +10197,4 @@ exports.updateProfile = updateProfile;
9852
10197
  exports.useDeviceLanguage = useDeviceLanguage;
9853
10198
  exports.verifyBeforeUpdateEmail = verifyBeforeUpdateEmail;
9854
10199
  exports.verifyPasswordResetCode = verifyPasswordResetCode;
9855
- //# sourceMappingURL=index-f15d4bca.js.map
10200
+ //# sourceMappingURL=index-2a5c9cce.js.map