@firebase/auth 0.22.0-canary.ea3849fff → 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-a4932583.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-e2867f33.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-5eca8e8e.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-ea49ccf6.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-e4b57fc2.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-3a67b88c.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-6ea1b9dd.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-a4932583.js.map +0 -1
  170. package/dist/cordova/popup_redirect-e2867f33.js.map +0 -1
  171. package/dist/esm2017/index-5eca8e8e.js.map +0 -1
  172. package/dist/esm5/index-ea49ccf6.js.map +0 -1
  173. package/dist/node/totp-e4b57fc2.js.map +0 -1
  174. package/dist/node-esm/totp-3a67b88c.js.map +0 -1
  175. package/dist/rn/phone-6ea1b9dd.js.map +0 -1
@@ -1,7 +1,7 @@
1
- import { ErrorFactory, deepEqual, isBrowserExtension, isMobileCordova, isReactNative, FirebaseError, querystring, getModularInstance, base64Decode, getUA, isIE, createSubscribe, querystringDecode, extractQuerystring, isEmpty, getExperimentalSetting, getDefaultEmulatorHost } from '@firebase/util';
1
+ import { ErrorFactory, isBrowserExtension, isMobileCordova, isReactNative, FirebaseError, querystring, getModularInstance, base64Decode, getUA, isIE, createSubscribe, deepEqual, querystringDecode, extractQuerystring, isEmpty, getExperimentalSetting, getDefaultEmulatorHost } from '@firebase/util';
2
2
  import { SDK_VERSION, _getProvider, _registerComponent, registerVersion, getApp } from '@firebase/app';
3
- import { Logger, LogLevel } from '@firebase/logger';
4
3
  import { __rest } from 'tslib';
4
+ import { Logger, LogLevel } from '@firebase/logger';
5
5
  import { Component } from '@firebase/component';
6
6
 
7
7
  /**
@@ -265,7 +265,15 @@ function _debugErrorMap() {
265
265
  ["already-initialized" /* AuthErrorCode.ALREADY_INITIALIZED */]: 'initializeAuth() has already been called with ' +
266
266
  'different options. To avoid this error, call initializeAuth() with the ' +
267
267
  'same options as when it was originally called, or call getAuth() to return the' +
268
- ' already initialized instance.'
268
+ ' already initialized instance.',
269
+ ["missing-recaptcha-token" /* AuthErrorCode.MISSING_RECAPTCHA_TOKEN */]: 'The reCAPTCHA token is missing when sending request to the backend.',
270
+ ["invalid-recaptcha-token" /* AuthErrorCode.INVALID_RECAPTCHA_TOKEN */]: 'The reCAPTCHA token is invalid when sending request to the backend.',
271
+ ["invalid-recaptcha-action" /* AuthErrorCode.INVALID_RECAPTCHA_ACTION */]: 'The reCAPTCHA action is invalid when sending request to the backend.',
272
+ ["recaptcha-not-enabled" /* AuthErrorCode.RECAPTCHA_NOT_ENABLED */]: 'reCAPTCHA Enterprise integration is not enabled for this project.',
273
+ ["missing-client-type" /* AuthErrorCode.MISSING_CLIENT_TYPE */]: 'The reCAPTCHA client type is missing when sending request to the backend.',
274
+ ["missing-recaptcha-version" /* AuthErrorCode.MISSING_RECAPTCHA_VERSION */]: 'The reCAPTCHA version is missing when sending request to the backend.',
275
+ ["invalid-req-type" /* AuthErrorCode.INVALID_REQ_TYPE */]: 'Invalid request parameters.',
276
+ ["invalid-recaptcha-version" /* AuthErrorCode.INVALID_RECAPTCHA_VERSION */]: 'The reCAPTCHA version is invalid when sending request to the backend.'
269
277
  };
270
278
  }
271
279
  function _prodErrorMap() {
@@ -401,7 +409,15 @@ const AUTH_ERROR_CODES_MAP_DO_NOT_USE_INTERNALLY = {
401
409
  USER_SIGNED_OUT: 'auth/user-signed-out',
402
410
  WEAK_PASSWORD: 'auth/weak-password',
403
411
  WEB_STORAGE_UNSUPPORTED: 'auth/web-storage-unsupported',
404
- ALREADY_INITIALIZED: 'auth/already-initialized'
412
+ ALREADY_INITIALIZED: 'auth/already-initialized',
413
+ RECAPTCHA_NOT_ENABLED: 'auth/recaptcha-not-enabled',
414
+ MISSING_RECAPTCHA_TOKEN: 'auth/missing-recaptcha-token',
415
+ INVALID_RECAPTCHA_TOKEN: 'auth/invalid-recaptcha-token',
416
+ INVALID_RECAPTCHA_ACTION: 'auth/invalid-recaptcha-action',
417
+ MISSING_CLIENT_TYPE: 'auth/missing-client-type',
418
+ MISSING_RECAPTCHA_VERSION: 'auth/missing-recaptcha-version',
419
+ INVALID_RECAPTCHA_VERSION: 'auth/invalid-recaptcha-version',
420
+ INVALID_REQ_TYPE: 'auth/invalid-req-type'
405
421
  };
406
422
 
407
423
  /**
@@ -516,103 +532,6 @@ function debugAssert(assertion, message) {
516
532
  }
517
533
  }
518
534
 
519
- /**
520
- * @license
521
- * Copyright 2020 Google LLC
522
- *
523
- * Licensed under the Apache License, Version 2.0 (the "License");
524
- * you may not use this file except in compliance with the License.
525
- * You may obtain a copy of the License at
526
- *
527
- * http://www.apache.org/licenses/LICENSE-2.0
528
- *
529
- * Unless required by applicable law or agreed to in writing, software
530
- * distributed under the License is distributed on an "AS IS" BASIS,
531
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
532
- * See the License for the specific language governing permissions and
533
- * limitations under the License.
534
- */
535
- const instanceCache = new Map();
536
- function _getInstance(cls) {
537
- debugAssert(cls instanceof Function, 'Expected a class definition');
538
- let instance = instanceCache.get(cls);
539
- if (instance) {
540
- debugAssert(instance instanceof cls, 'Instance stored in cache mismatched with class');
541
- return instance;
542
- }
543
- instance = new cls();
544
- instanceCache.set(cls, instance);
545
- return instance;
546
- }
547
-
548
- /**
549
- * @license
550
- * Copyright 2020 Google LLC
551
- *
552
- * Licensed under the Apache License, Version 2.0 (the "License");
553
- * you may not use this file except in compliance with the License.
554
- * You may obtain a copy of the License at
555
- *
556
- * http://www.apache.org/licenses/LICENSE-2.0
557
- *
558
- * Unless required by applicable law or agreed to in writing, software
559
- * distributed under the License is distributed on an "AS IS" BASIS,
560
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
561
- * See the License for the specific language governing permissions and
562
- * limitations under the License.
563
- */
564
- /**
565
- * Initializes an {@link Auth} instance with fine-grained control over
566
- * {@link Dependencies}.
567
- *
568
- * @remarks
569
- *
570
- * This function allows more control over the {@link Auth} instance than
571
- * {@link getAuth}. `getAuth` uses platform-specific defaults to supply
572
- * the {@link Dependencies}. In general, `getAuth` is the easiest way to
573
- * initialize Auth and works for most use cases. Use `initializeAuth` if you
574
- * need control over which persistence layer is used, or to minimize bundle
575
- * size if you're not using either `signInWithPopup` or `signInWithRedirect`.
576
- *
577
- * For example, if your app only uses anonymous accounts and you only want
578
- * accounts saved for the current session, initialize `Auth` with:
579
- *
580
- * ```js
581
- * const auth = initializeAuth(app, {
582
- * persistence: browserSessionPersistence,
583
- * popupRedirectResolver: undefined,
584
- * });
585
- * ```
586
- *
587
- * @public
588
- */
589
- function initializeAuth(app, deps) {
590
- const provider = _getProvider(app, 'auth');
591
- if (provider.isInitialized()) {
592
- const auth = provider.getImmediate();
593
- const initialOptions = provider.getOptions();
594
- if (deepEqual(initialOptions, deps !== null && deps !== void 0 ? deps : {})) {
595
- return auth;
596
- }
597
- else {
598
- _fail(auth, "already-initialized" /* AuthErrorCode.ALREADY_INITIALIZED */);
599
- }
600
- }
601
- const auth = provider.initialize({ options: deps });
602
- return auth;
603
- }
604
- function _initializeAuthInstance(auth, deps) {
605
- const persistence = (deps === null || deps === void 0 ? void 0 : deps.persistence) || [];
606
- const hierarchy = (Array.isArray(persistence) ? persistence : [persistence]).map(_getInstance);
607
- if (deps === null || deps === void 0 ? void 0 : deps.errorMap) {
608
- auth._updateErrorMap(deps.errorMap);
609
- }
610
- // This promise is intended to float; auth initialization happens in the
611
- // background, meanwhile the auth object may be used by the app.
612
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
613
- auth._initializeWithPersistence(hierarchy, deps === null || deps === void 0 ? void 0 : deps.popupRedirectResolver);
614
- }
615
-
616
535
  /**
617
536
  * @license
618
537
  * Copyright 2020 Google LLC
@@ -891,7 +810,16 @@ const SERVER_ERROR_MAP = {
891
810
  ["SECOND_FACTOR_EXISTS" /* ServerError.SECOND_FACTOR_EXISTS */]: "second-factor-already-in-use" /* AuthErrorCode.SECOND_FACTOR_ALREADY_ENROLLED */,
892
811
  ["SECOND_FACTOR_LIMIT_EXCEEDED" /* ServerError.SECOND_FACTOR_LIMIT_EXCEEDED */]: "maximum-second-factor-count-exceeded" /* AuthErrorCode.SECOND_FACTOR_LIMIT_EXCEEDED */,
893
812
  // Blocking functions related errors.
894
- ["BLOCKING_FUNCTION_ERROR_RESPONSE" /* ServerError.BLOCKING_FUNCTION_ERROR_RESPONSE */]: "internal-error" /* AuthErrorCode.INTERNAL_ERROR */
813
+ ["BLOCKING_FUNCTION_ERROR_RESPONSE" /* ServerError.BLOCKING_FUNCTION_ERROR_RESPONSE */]: "internal-error" /* AuthErrorCode.INTERNAL_ERROR */,
814
+ // Recaptcha related errors.
815
+ ["RECAPTCHA_NOT_ENABLED" /* ServerError.RECAPTCHA_NOT_ENABLED */]: "recaptcha-not-enabled" /* AuthErrorCode.RECAPTCHA_NOT_ENABLED */,
816
+ ["MISSING_RECAPTCHA_TOKEN" /* ServerError.MISSING_RECAPTCHA_TOKEN */]: "missing-recaptcha-token" /* AuthErrorCode.MISSING_RECAPTCHA_TOKEN */,
817
+ ["INVALID_RECAPTCHA_TOKEN" /* ServerError.INVALID_RECAPTCHA_TOKEN */]: "invalid-recaptcha-token" /* AuthErrorCode.INVALID_RECAPTCHA_TOKEN */,
818
+ ["INVALID_RECAPTCHA_ACTION" /* ServerError.INVALID_RECAPTCHA_ACTION */]: "invalid-recaptcha-action" /* AuthErrorCode.INVALID_RECAPTCHA_ACTION */,
819
+ ["MISSING_CLIENT_TYPE" /* ServerError.MISSING_CLIENT_TYPE */]: "missing-client-type" /* AuthErrorCode.MISSING_CLIENT_TYPE */,
820
+ ["MISSING_RECAPTCHA_VERSION" /* ServerError.MISSING_RECAPTCHA_VERSION */]: "missing-recaptcha-version" /* AuthErrorCode.MISSING_RECAPTCHA_VERSION */,
821
+ ["INVALID_RECAPTCHA_VERSION" /* ServerError.INVALID_RECAPTCHA_VERSION */]: "invalid-recaptcha-version" /* AuthErrorCode.INVALID_RECAPTCHA_VERSION */,
822
+ ["INVALID_REQ_TYPE" /* ServerError.INVALID_REQ_TYPE */]: "invalid-req-type" /* AuthErrorCode.INVALID_REQ_TYPE */
895
823
  };
896
824
 
897
825
  /**
@@ -1793,6 +1721,35 @@ class UserImpl {
1793
1721
  }
1794
1722
  }
1795
1723
 
1724
+ /**
1725
+ * @license
1726
+ * Copyright 2020 Google LLC
1727
+ *
1728
+ * Licensed under the Apache License, Version 2.0 (the "License");
1729
+ * you may not use this file except in compliance with the License.
1730
+ * You may obtain a copy of the License at
1731
+ *
1732
+ * http://www.apache.org/licenses/LICENSE-2.0
1733
+ *
1734
+ * Unless required by applicable law or agreed to in writing, software
1735
+ * distributed under the License is distributed on an "AS IS" BASIS,
1736
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1737
+ * See the License for the specific language governing permissions and
1738
+ * limitations under the License.
1739
+ */
1740
+ const instanceCache = new Map();
1741
+ function _getInstance(cls) {
1742
+ debugAssert(cls instanceof Function, 'Expected a class definition');
1743
+ let instance = instanceCache.get(cls);
1744
+ if (instance) {
1745
+ debugAssert(instance instanceof cls, 'Instance stored in cache mismatched with class');
1746
+ return instance;
1747
+ }
1748
+ instance = new cls();
1749
+ instanceCache.set(cls, instance);
1750
+ return instance;
1751
+ }
1752
+
1796
1753
  /**
1797
1754
  * @license
1798
1755
  * Copyright 2019 Google LLC
@@ -2134,6 +2091,242 @@ function _getClientVersion(clientPlatform, frameworks = []) {
2134
2091
  return `${reportedPlatform}/${"JsCore" /* ClientImplementation.CORE */}/${SDK_VERSION}/${reportedFrameworks}`;
2135
2092
  }
2136
2093
 
2094
+ /**
2095
+ * @license
2096
+ * Copyright 2020 Google LLC
2097
+ *
2098
+ * Licensed under the Apache License, Version 2.0 (the "License");
2099
+ * you may not use this file except in compliance with the License.
2100
+ * You may obtain a copy of the License at
2101
+ *
2102
+ * http://www.apache.org/licenses/LICENSE-2.0
2103
+ *
2104
+ * Unless required by applicable law or agreed to in writing, software
2105
+ * distributed under the License is distributed on an "AS IS" BASIS,
2106
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2107
+ * See the License for the specific language governing permissions and
2108
+ * limitations under the License.
2109
+ */
2110
+ async function getRecaptchaParams(auth) {
2111
+ return ((await _performApiRequest(auth, "GET" /* HttpMethod.GET */, "/v1/recaptchaParams" /* Endpoint.GET_RECAPTCHA_PARAM */)).recaptchaSiteKey || '');
2112
+ }
2113
+ async function getRecaptchaConfig(auth, request) {
2114
+ return _performApiRequest(auth, "GET" /* HttpMethod.GET */, "/v2/recaptchaConfig" /* Endpoint.GET_RECAPTCHA_CONFIG */, _addTidIfNecessary(auth, request));
2115
+ }
2116
+
2117
+ /**
2118
+ * @license
2119
+ * Copyright 2020 Google LLC
2120
+ *
2121
+ * Licensed under the Apache License, Version 2.0 (the "License");
2122
+ * you may not use this file except in compliance with the License.
2123
+ * You may obtain a copy of the License at
2124
+ *
2125
+ * http://www.apache.org/licenses/LICENSE-2.0
2126
+ *
2127
+ * Unless required by applicable law or agreed to in writing, software
2128
+ * distributed under the License is distributed on an "AS IS" BASIS,
2129
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2130
+ * See the License for the specific language governing permissions and
2131
+ * limitations under the License.
2132
+ */
2133
+ function isV2(grecaptcha) {
2134
+ return (grecaptcha !== undefined &&
2135
+ grecaptcha.getResponse !== undefined);
2136
+ }
2137
+ function isEnterprise(grecaptcha) {
2138
+ return (grecaptcha !== undefined &&
2139
+ grecaptcha.enterprise !== undefined);
2140
+ }
2141
+ class RecaptchaConfig {
2142
+ constructor(response) {
2143
+ /**
2144
+ * The reCAPTCHA site key.
2145
+ */
2146
+ this.siteKey = '';
2147
+ /**
2148
+ * The reCAPTCHA enablement status of the {@link EmailAuthProvider} for the current tenant.
2149
+ */
2150
+ this.emailPasswordEnabled = false;
2151
+ if (response.recaptchaKey === undefined) {
2152
+ throw new Error('recaptchaKey undefined');
2153
+ }
2154
+ // Example response.recaptchaKey: "projects/proj123/keys/sitekey123"
2155
+ this.siteKey = response.recaptchaKey.split('/')[3];
2156
+ this.emailPasswordEnabled = response.recaptchaEnforcementState.some(enforcementState => enforcementState.provider === 'EMAIL_PASSWORD_PROVIDER' &&
2157
+ enforcementState.enforcementState !== 'OFF');
2158
+ }
2159
+ }
2160
+
2161
+ /**
2162
+ * @license
2163
+ * Copyright 2020 Google LLC
2164
+ *
2165
+ * Licensed under the Apache License, Version 2.0 (the "License");
2166
+ * you may not use this file except in compliance with the License.
2167
+ * You may obtain a copy of the License at
2168
+ *
2169
+ * http://www.apache.org/licenses/LICENSE-2.0
2170
+ *
2171
+ * Unless required by applicable law or agreed to in writing, software
2172
+ * distributed under the License is distributed on an "AS IS" BASIS,
2173
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2174
+ * See the License for the specific language governing permissions and
2175
+ * limitations under the License.
2176
+ */
2177
+ function getScriptParentElement() {
2178
+ var _a, _b;
2179
+ return (_b = (_a = document.getElementsByTagName('head')) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : document;
2180
+ }
2181
+ function _loadJS(url) {
2182
+ // TODO: consider adding timeout support & cancellation
2183
+ return new Promise((resolve, reject) => {
2184
+ const el = document.createElement('script');
2185
+ el.setAttribute('src', url);
2186
+ el.onload = resolve;
2187
+ el.onerror = e => {
2188
+ const error = _createError("internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
2189
+ error.customData = e;
2190
+ reject(error);
2191
+ };
2192
+ el.type = 'text/javascript';
2193
+ el.charset = 'UTF-8';
2194
+ getScriptParentElement().appendChild(el);
2195
+ });
2196
+ }
2197
+ function _generateCallbackName(prefix) {
2198
+ return `__${prefix}${Math.floor(Math.random() * 1000000)}`;
2199
+ }
2200
+
2201
+ /* eslint-disable @typescript-eslint/no-require-imports */
2202
+ const RECAPTCHA_ENTERPRISE_URL = 'https://www.google.com/recaptcha/enterprise.js?render=';
2203
+ const RECAPTCHA_ENTERPRISE_VERIFIER_TYPE = 'recaptcha-enterprise';
2204
+ class RecaptchaEnterpriseVerifier {
2205
+ /**
2206
+ *
2207
+ * @param authExtern - The corresponding Firebase {@link Auth} instance.
2208
+ *
2209
+ */
2210
+ constructor(authExtern) {
2211
+ /**
2212
+ * Identifies the type of application verifier (e.g. "recaptcha-enterprise").
2213
+ */
2214
+ this.type = RECAPTCHA_ENTERPRISE_VERIFIER_TYPE;
2215
+ this.auth = _castAuth(authExtern);
2216
+ }
2217
+ /**
2218
+ * Executes the verification process.
2219
+ *
2220
+ * @returns A Promise for a token that can be used to assert the validity of a request.
2221
+ */
2222
+ async verify(action = 'verify', forceRefresh = false) {
2223
+ async function retrieveSiteKey(auth) {
2224
+ if (!forceRefresh) {
2225
+ if (auth.tenantId == null && auth._agentRecaptchaConfig != null) {
2226
+ return auth._agentRecaptchaConfig.siteKey;
2227
+ }
2228
+ if (auth.tenantId != null &&
2229
+ auth._tenantRecaptchaConfigs[auth.tenantId] !== undefined) {
2230
+ return auth._tenantRecaptchaConfigs[auth.tenantId].siteKey;
2231
+ }
2232
+ }
2233
+ return new Promise(async (resolve, reject) => {
2234
+ getRecaptchaConfig(auth, {
2235
+ clientType: "CLIENT_TYPE_WEB" /* RecaptchaClientType.WEB */,
2236
+ version: "RECAPTCHA_ENTERPRISE" /* RecaptchaVersion.ENTERPRISE */
2237
+ })
2238
+ .then(response => {
2239
+ if (response.recaptchaKey === undefined) {
2240
+ reject(new Error('recaptcha Enterprise site key undefined'));
2241
+ }
2242
+ else {
2243
+ const config = new RecaptchaConfig(response);
2244
+ if (auth.tenantId == null) {
2245
+ auth._agentRecaptchaConfig = config;
2246
+ }
2247
+ else {
2248
+ auth._tenantRecaptchaConfigs[auth.tenantId] = config;
2249
+ }
2250
+ return resolve(config.siteKey);
2251
+ }
2252
+ })
2253
+ .catch(error => {
2254
+ reject(error);
2255
+ });
2256
+ });
2257
+ }
2258
+ function retrieveRecaptchaToken(siteKey, resolve, reject) {
2259
+ const grecaptcha = window.grecaptcha;
2260
+ if (isEnterprise(grecaptcha)) {
2261
+ grecaptcha.enterprise.ready(() => {
2262
+ try {
2263
+ grecaptcha.enterprise
2264
+ .execute(siteKey, { action })
2265
+ .then(token => {
2266
+ resolve(token);
2267
+ })
2268
+ .catch(error => {
2269
+ reject(error);
2270
+ });
2271
+ }
2272
+ catch (error) {
2273
+ reject(error);
2274
+ }
2275
+ });
2276
+ }
2277
+ else {
2278
+ reject(Error('No reCAPTCHA enterprise script loaded.'));
2279
+ }
2280
+ }
2281
+ return new Promise((resolve, reject) => {
2282
+ retrieveSiteKey(this.auth)
2283
+ .then(siteKey => {
2284
+ if (!forceRefresh && isEnterprise(window.grecaptcha)) {
2285
+ retrieveRecaptchaToken(siteKey, resolve, reject);
2286
+ }
2287
+ else {
2288
+ if (typeof window === 'undefined') {
2289
+ reject(new Error('RecaptchaVerifier is only supported in browser'));
2290
+ return;
2291
+ }
2292
+ _loadJS(RECAPTCHA_ENTERPRISE_URL + siteKey)
2293
+ .then(() => {
2294
+ retrieveRecaptchaToken(siteKey, resolve, reject);
2295
+ })
2296
+ .catch(error => {
2297
+ reject(error);
2298
+ });
2299
+ }
2300
+ })
2301
+ .catch(error => {
2302
+ reject(error);
2303
+ });
2304
+ });
2305
+ }
2306
+ }
2307
+ async function injectRecaptchaFields(auth, request, action, captchaResp = false) {
2308
+ const verifier = new RecaptchaEnterpriseVerifier(auth);
2309
+ let captchaResponse;
2310
+ try {
2311
+ captchaResponse = await verifier.verify(action);
2312
+ }
2313
+ catch (error) {
2314
+ captchaResponse = await verifier.verify(action, true);
2315
+ }
2316
+ const newRequest = Object.assign({}, request);
2317
+ if (!captchaResp) {
2318
+ Object.assign(newRequest, { captchaResponse });
2319
+ }
2320
+ else {
2321
+ Object.assign(newRequest, { 'captchaResp': captchaResponse });
2322
+ }
2323
+ Object.assign(newRequest, { 'clientType': "CLIENT_TYPE_WEB" /* RecaptchaClientType.WEB */ });
2324
+ Object.assign(newRequest, {
2325
+ 'recaptchaVersion': "RECAPTCHA_ENTERPRISE" /* RecaptchaVersion.ENTERPRISE */
2326
+ });
2327
+ return newRequest;
2328
+ }
2329
+
2137
2330
  /**
2138
2331
  * @license
2139
2332
  * Copyright 2022 Google LLC
@@ -2253,6 +2446,8 @@ class AuthImpl {
2253
2446
  this._initializationPromise = null;
2254
2447
  this._popupRedirectResolver = null;
2255
2448
  this._errorFactory = _DEFAULT_AUTH_ERROR_FACTORY;
2449
+ this._agentRecaptchaConfig = null;
2450
+ this._tenantRecaptchaConfigs = {};
2256
2451
  // Tracks the last notified UID for state change listeners to prevent
2257
2452
  // repeated calls to the callbacks. Undefined means it's never been
2258
2453
  // called, whereas null means it's been called with a signed out user
@@ -2472,6 +2667,31 @@ class AuthImpl {
2472
2667
  await this.assertedPersistence.setPersistence(_getInstance(persistence));
2473
2668
  });
2474
2669
  }
2670
+ async initializeRecaptchaConfig() {
2671
+ const response = await getRecaptchaConfig(this, {
2672
+ clientType: "CLIENT_TYPE_WEB" /* RecaptchaClientType.WEB */,
2673
+ version: "RECAPTCHA_ENTERPRISE" /* RecaptchaVersion.ENTERPRISE */
2674
+ });
2675
+ const config = new RecaptchaConfig(response);
2676
+ if (this.tenantId == null) {
2677
+ this._agentRecaptchaConfig = config;
2678
+ }
2679
+ else {
2680
+ this._tenantRecaptchaConfigs[this.tenantId] = config;
2681
+ }
2682
+ if (config.emailPasswordEnabled) {
2683
+ const verifier = new RecaptchaEnterpriseVerifier(this);
2684
+ void verifier.verify();
2685
+ }
2686
+ }
2687
+ _getRecaptchaConfig() {
2688
+ if (this.tenantId == null) {
2689
+ return this._agentRecaptchaConfig;
2690
+ }
2691
+ else {
2692
+ return this._tenantRecaptchaConfigs[this.tenantId];
2693
+ }
2694
+ }
2475
2695
  _getPersistence() {
2476
2696
  return this.assertedPersistence.persistence.type;
2477
2697
  }
@@ -2694,6 +2914,74 @@ class Subscription {
2694
2914
  }
2695
2915
  }
2696
2916
 
2917
+ /**
2918
+ * @license
2919
+ * Copyright 2020 Google LLC
2920
+ *
2921
+ * Licensed under the Apache License, Version 2.0 (the "License");
2922
+ * you may not use this file except in compliance with the License.
2923
+ * You may obtain a copy of the License at
2924
+ *
2925
+ * http://www.apache.org/licenses/LICENSE-2.0
2926
+ *
2927
+ * Unless required by applicable law or agreed to in writing, software
2928
+ * distributed under the License is distributed on an "AS IS" BASIS,
2929
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2930
+ * See the License for the specific language governing permissions and
2931
+ * limitations under the License.
2932
+ */
2933
+ /**
2934
+ * Initializes an {@link Auth} instance with fine-grained control over
2935
+ * {@link Dependencies}.
2936
+ *
2937
+ * @remarks
2938
+ *
2939
+ * This function allows more control over the {@link Auth} instance than
2940
+ * {@link getAuth}. `getAuth` uses platform-specific defaults to supply
2941
+ * the {@link Dependencies}. In general, `getAuth` is the easiest way to
2942
+ * initialize Auth and works for most use cases. Use `initializeAuth` if you
2943
+ * need control over which persistence layer is used, or to minimize bundle
2944
+ * size if you're not using either `signInWithPopup` or `signInWithRedirect`.
2945
+ *
2946
+ * For example, if your app only uses anonymous accounts and you only want
2947
+ * accounts saved for the current session, initialize `Auth` with:
2948
+ *
2949
+ * ```js
2950
+ * const auth = initializeAuth(app, {
2951
+ * persistence: browserSessionPersistence,
2952
+ * popupRedirectResolver: undefined,
2953
+ * });
2954
+ * ```
2955
+ *
2956
+ * @public
2957
+ */
2958
+ function initializeAuth(app, deps) {
2959
+ const provider = _getProvider(app, 'auth');
2960
+ if (provider.isInitialized()) {
2961
+ const auth = provider.getImmediate();
2962
+ const initialOptions = provider.getOptions();
2963
+ if (deepEqual(initialOptions, deps !== null && deps !== void 0 ? deps : {})) {
2964
+ return auth;
2965
+ }
2966
+ else {
2967
+ _fail(auth, "already-initialized" /* AuthErrorCode.ALREADY_INITIALIZED */);
2968
+ }
2969
+ }
2970
+ const auth = provider.initialize({ options: deps });
2971
+ return auth;
2972
+ }
2973
+ function _initializeAuthInstance(auth, deps) {
2974
+ const persistence = (deps === null || deps === void 0 ? void 0 : deps.persistence) || [];
2975
+ const hierarchy = (Array.isArray(persistence) ? persistence : [persistence]).map(_getInstance);
2976
+ if (deps === null || deps === void 0 ? void 0 : deps.errorMap) {
2977
+ auth._updateErrorMap(deps.errorMap);
2978
+ }
2979
+ // This promise is intended to float; auth initialization happens in the
2980
+ // background, meanwhile the auth object may be used by the app.
2981
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
2982
+ auth._initializeWithPersistence(hierarchy, deps === null || deps === void 0 ? void 0 : deps.popupRedirectResolver);
2983
+ }
2984
+
2697
2985
  /**
2698
2986
  * Changes the {@link Auth} instance to communicate with the Firebase Auth Emulator, instead of production
2699
2987
  * Firebase Auth services.
@@ -3033,13 +3321,31 @@ class EmailAuthCredential extends AuthCredential {
3033
3321
  }
3034
3322
  /** @internal */
3035
3323
  async _getIdTokenResponse(auth) {
3324
+ var _a;
3036
3325
  switch (this.signInMethod) {
3037
3326
  case "password" /* SignInMethod.EMAIL_PASSWORD */:
3038
- return signInWithPassword(auth, {
3327
+ const request = {
3039
3328
  returnSecureToken: true,
3040
3329
  email: this._email,
3041
- password: this._password
3042
- });
3330
+ password: this._password,
3331
+ clientType: "CLIENT_TYPE_WEB" /* RecaptchaClientType.WEB */
3332
+ };
3333
+ if ((_a = auth._getRecaptchaConfig()) === null || _a === void 0 ? void 0 : _a.emailPasswordEnabled) {
3334
+ const requestWithRecaptcha = await injectRecaptchaFields(auth, request, "signInWithPassword" /* RecaptchaActionName.SIGN_IN_WITH_PASSWORD */);
3335
+ return signInWithPassword(auth, requestWithRecaptcha);
3336
+ }
3337
+ else {
3338
+ return signInWithPassword(auth, request).catch(async (error) => {
3339
+ if (error.code === `auth/${"missing-recaptcha-token" /* AuthErrorCode.MISSING_RECAPTCHA_TOKEN */}`) {
3340
+ 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.');
3341
+ const requestWithRecaptcha = await injectRecaptchaFields(auth, request, "signInWithPassword" /* RecaptchaActionName.SIGN_IN_WITH_PASSWORD */);
3342
+ return signInWithPassword(auth, requestWithRecaptcha);
3343
+ }
3344
+ else {
3345
+ return Promise.reject(error);
3346
+ }
3347
+ });
3348
+ }
3043
3349
  case "emailLink" /* SignInMethod.EMAIL_LINK */:
3044
3350
  return signInWithEmailLink$1(auth, {
3045
3351
  email: this._email,
@@ -4998,15 +5304,39 @@ function _setActionCodeSettingsOnRequest(auth, request, actionCodeSettings) {
4998
5304
  * @public
4999
5305
  */
5000
5306
  async function sendPasswordResetEmail(auth, email, actionCodeSettings) {
5001
- const authModular = getModularInstance(auth);
5307
+ var _a;
5308
+ const authInternal = _castAuth(auth);
5002
5309
  const request = {
5003
5310
  requestType: "PASSWORD_RESET" /* ActionCodeOperation.PASSWORD_RESET */,
5004
- email
5311
+ email,
5312
+ clientType: "CLIENT_TYPE_WEB" /* RecaptchaClientType.WEB */
5005
5313
  };
5006
- if (actionCodeSettings) {
5007
- _setActionCodeSettingsOnRequest(authModular, request, actionCodeSettings);
5314
+ if ((_a = authInternal._getRecaptchaConfig()) === null || _a === void 0 ? void 0 : _a.emailPasswordEnabled) {
5315
+ const requestWithRecaptcha = await injectRecaptchaFields(authInternal, request, "getOobCode" /* RecaptchaActionName.GET_OOB_CODE */, true);
5316
+ if (actionCodeSettings) {
5317
+ _setActionCodeSettingsOnRequest(authInternal, requestWithRecaptcha, actionCodeSettings);
5318
+ }
5319
+ await sendPasswordResetEmail$1(authInternal, requestWithRecaptcha);
5320
+ }
5321
+ else {
5322
+ if (actionCodeSettings) {
5323
+ _setActionCodeSettingsOnRequest(authInternal, request, actionCodeSettings);
5324
+ }
5325
+ await sendPasswordResetEmail$1(authInternal, request)
5326
+ .catch(async (error) => {
5327
+ if (error.code === `auth/${"missing-recaptcha-token" /* AuthErrorCode.MISSING_RECAPTCHA_TOKEN */}`) {
5328
+ console.log('Password resets are protected by reCAPTCHA for this project. Automatically triggering the reCAPTCHA flow and restarting the password reset flow.');
5329
+ const requestWithRecaptcha = await injectRecaptchaFields(authInternal, request, "getOobCode" /* RecaptchaActionName.GET_OOB_CODE */, true);
5330
+ if (actionCodeSettings) {
5331
+ _setActionCodeSettingsOnRequest(authInternal, requestWithRecaptcha, actionCodeSettings);
5332
+ }
5333
+ await sendPasswordResetEmail$1(authInternal, requestWithRecaptcha);
5334
+ }
5335
+ else {
5336
+ return Promise.reject(error);
5337
+ }
5338
+ });
5008
5339
  }
5009
- await sendPasswordResetEmail$1(authModular, request);
5010
5340
  }
5011
5341
  /**
5012
5342
  * Completes the password reset process, given a confirmation code and new password.
@@ -5119,11 +5449,33 @@ async function verifyPasswordResetCode(auth, code) {
5119
5449
  * @public
5120
5450
  */
5121
5451
  async function createUserWithEmailAndPassword(auth, email, password) {
5452
+ var _a;
5122
5453
  const authInternal = _castAuth(auth);
5123
- const response = await signUp(authInternal, {
5454
+ const request = {
5124
5455
  returnSecureToken: true,
5125
5456
  email,
5126
- password
5457
+ password,
5458
+ clientType: "CLIENT_TYPE_WEB" /* RecaptchaClientType.WEB */
5459
+ };
5460
+ let signUpResponse;
5461
+ if ((_a = authInternal._getRecaptchaConfig()) === null || _a === void 0 ? void 0 : _a.emailPasswordEnabled) {
5462
+ const requestWithRecaptcha = await injectRecaptchaFields(authInternal, request, "signUpPassword" /* RecaptchaActionName.SIGN_UP_PASSWORD */);
5463
+ signUpResponse = signUp(authInternal, requestWithRecaptcha);
5464
+ }
5465
+ else {
5466
+ signUpResponse = signUp(authInternal, request).catch(async (error) => {
5467
+ if (error.code === `auth/${"missing-recaptcha-token" /* AuthErrorCode.MISSING_RECAPTCHA_TOKEN */}`) {
5468
+ console.log('Sign-up is protected by reCAPTCHA for this project. Automatically triggering the reCAPTCHA flow and restarting the sign-up flow.');
5469
+ const requestWithRecaptcha = await injectRecaptchaFields(authInternal, request, "signUpPassword" /* RecaptchaActionName.SIGN_UP_PASSWORD */);
5470
+ return signUp(authInternal, requestWithRecaptcha);
5471
+ }
5472
+ else {
5473
+ return Promise.reject(error);
5474
+ }
5475
+ });
5476
+ }
5477
+ const response = await signUpResponse.catch(error => {
5478
+ return Promise.reject(error);
5127
5479
  });
5128
5480
  const userCredential = await UserCredentialImpl._fromIdTokenResponse(authInternal, "signIn" /* OperationType.SIGN_IN */, response);
5129
5481
  await authInternal._updateCurrentUser(userCredential.user);
@@ -5204,16 +5556,39 @@ function signInWithEmailAndPassword(auth, email, password) {
5204
5556
  * @public
5205
5557
  */
5206
5558
  async function sendSignInLinkToEmail(auth, email, actionCodeSettings) {
5207
- const authModular = getModularInstance(auth);
5559
+ var _a;
5560
+ const authInternal = _castAuth(auth);
5208
5561
  const request = {
5209
5562
  requestType: "EMAIL_SIGNIN" /* ActionCodeOperation.EMAIL_SIGNIN */,
5210
- email
5563
+ email,
5564
+ clientType: "CLIENT_TYPE_WEB" /* RecaptchaClientType.WEB */
5211
5565
  };
5212
- _assert(actionCodeSettings.handleCodeInApp, authModular, "argument-error" /* AuthErrorCode.ARGUMENT_ERROR */);
5213
- if (actionCodeSettings) {
5214
- _setActionCodeSettingsOnRequest(authModular, request, actionCodeSettings);
5566
+ function setActionCodeSettings(request, actionCodeSettings) {
5567
+ _assert(actionCodeSettings.handleCodeInApp, authInternal, "argument-error" /* AuthErrorCode.ARGUMENT_ERROR */);
5568
+ if (actionCodeSettings) {
5569
+ _setActionCodeSettingsOnRequest(authInternal, request, actionCodeSettings);
5570
+ }
5571
+ }
5572
+ if ((_a = authInternal._getRecaptchaConfig()) === null || _a === void 0 ? void 0 : _a.emailPasswordEnabled) {
5573
+ const requestWithRecaptcha = await injectRecaptchaFields(authInternal, request, "getOobCode" /* RecaptchaActionName.GET_OOB_CODE */, true);
5574
+ setActionCodeSettings(requestWithRecaptcha, actionCodeSettings);
5575
+ await sendSignInLinkToEmail$1(authInternal, requestWithRecaptcha);
5576
+ }
5577
+ else {
5578
+ setActionCodeSettings(request, actionCodeSettings);
5579
+ await sendSignInLinkToEmail$1(authInternal, request)
5580
+ .catch(async (error) => {
5581
+ if (error.code === `auth/${"missing-recaptcha-token" /* AuthErrorCode.MISSING_RECAPTCHA_TOKEN */}`) {
5582
+ console.log('Email link sign-in is protected by reCAPTCHA for this project. Automatically triggering the reCAPTCHA flow and restarting the sign-in flow.');
5583
+ const requestWithRecaptcha = await injectRecaptchaFields(authInternal, request, "getOobCode" /* RecaptchaActionName.GET_OOB_CODE */, true);
5584
+ setActionCodeSettings(requestWithRecaptcha, actionCodeSettings);
5585
+ await sendSignInLinkToEmail$1(authInternal, requestWithRecaptcha);
5586
+ }
5587
+ else {
5588
+ return Promise.reject(error);
5589
+ }
5590
+ });
5215
5591
  }
5216
- await sendSignInLinkToEmail$1(authModular, request);
5217
5592
  }
5218
5593
  /**
5219
5594
  * Checks if an incoming link is a sign-in with email link suitable for {@link signInWithEmailLink}.
@@ -5708,6 +6083,35 @@ function getAdditionalUserInfo(userCredential) {
5708
6083
  function setPersistence(auth, persistence) {
5709
6084
  return getModularInstance(auth).setPersistence(persistence);
5710
6085
  }
6086
+ /**
6087
+ * Loads the reCAPTCHA configuration into the `Auth` instance.
6088
+ *
6089
+ * @remarks
6090
+ * This will load the reCAPTCHA config, which indicates whether the reCAPTCHA
6091
+ * verification flow should be triggered for each auth provider, into the
6092
+ * current Auth session.
6093
+ *
6094
+ * If initializeRecaptchaConfig() is not invoked, the auth flow will always start
6095
+ * without reCAPTCHA verification. If the provider is configured to require reCAPTCHA
6096
+ * verification, the SDK will transparently load the reCAPTCHA config and restart the
6097
+ * auth flows.
6098
+ *
6099
+ * Thus, by calling this optional method, you will reduce the latency of future auth flows.
6100
+ * Loading the reCAPTCHA config early will also enhance the signal collected by reCAPTCHA.
6101
+ *
6102
+ * @example
6103
+ * ```javascript
6104
+ * initializeRecaptchaConfig(auth);
6105
+ * ```
6106
+ *
6107
+ * @param auth - The {@link Auth} instance.
6108
+ *
6109
+ * @public
6110
+ */
6111
+ function initializeRecaptchaConfig(auth) {
6112
+ const authInternal = _castAuth(auth);
6113
+ return authInternal.initializeRecaptchaConfig();
6114
+ }
5711
6115
  /**
5712
6116
  * Adds an observer for changes to the signed-in user's ID token.
5713
6117
  *
@@ -7053,66 +7457,6 @@ function finalizeSignInTotpMfa(auth, request) {
7053
7457
  return _performApiRequest(auth, "POST" /* HttpMethod.POST */, "/v2/accounts/mfaSignIn:finalize" /* Endpoint.FINALIZE_MFA_SIGN_IN */, _addTidIfNecessary(auth, request));
7054
7458
  }
7055
7459
 
7056
- /**
7057
- * @license
7058
- * Copyright 2020 Google LLC
7059
- *
7060
- * Licensed under the Apache License, Version 2.0 (the "License");
7061
- * you may not use this file except in compliance with the License.
7062
- * You may obtain a copy of the License at
7063
- *
7064
- * http://www.apache.org/licenses/LICENSE-2.0
7065
- *
7066
- * Unless required by applicable law or agreed to in writing, software
7067
- * distributed under the License is distributed on an "AS IS" BASIS,
7068
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7069
- * See the License for the specific language governing permissions and
7070
- * limitations under the License.
7071
- */
7072
- async function getRecaptchaParams(auth) {
7073
- return ((await _performApiRequest(auth, "GET" /* HttpMethod.GET */, "/v1/recaptchaParams" /* Endpoint.GET_RECAPTCHA_PARAM */)).recaptchaSiteKey || '');
7074
- }
7075
-
7076
- /**
7077
- * @license
7078
- * Copyright 2020 Google LLC
7079
- *
7080
- * Licensed under the Apache License, Version 2.0 (the "License");
7081
- * you may not use this file except in compliance with the License.
7082
- * You may obtain a copy of the License at
7083
- *
7084
- * http://www.apache.org/licenses/LICENSE-2.0
7085
- *
7086
- * Unless required by applicable law or agreed to in writing, software
7087
- * distributed under the License is distributed on an "AS IS" BASIS,
7088
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7089
- * See the License for the specific language governing permissions and
7090
- * limitations under the License.
7091
- */
7092
- function getScriptParentElement() {
7093
- var _a, _b;
7094
- return (_b = (_a = document.getElementsByTagName('head')) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : document;
7095
- }
7096
- function _loadJS(url) {
7097
- // TODO: consider adding timeout support & cancellation
7098
- return new Promise((resolve, reject) => {
7099
- const el = document.createElement('script');
7100
- el.setAttribute('src', url);
7101
- el.onload = resolve;
7102
- el.onerror = e => {
7103
- const error = _createError("internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
7104
- error.customData = e;
7105
- reject(error);
7106
- };
7107
- el.type = 'text/javascript';
7108
- el.charset = 'UTF-8';
7109
- getScriptParentElement().appendChild(el);
7110
- });
7111
- }
7112
- function _generateCallbackName(prefix) {
7113
- return `__${prefix}${Math.floor(Math.random() * 1000000)}`;
7114
- }
7115
-
7116
7460
  /**
7117
7461
  * @license
7118
7462
  * Copyright 2020 Google LLC
@@ -7279,7 +7623,7 @@ class ReCaptchaLoaderImpl {
7279
7623
  }
7280
7624
  load(auth, hl = '') {
7281
7625
  _assert(isHostLanguageValid(hl), auth, "argument-error" /* AuthErrorCode.ARGUMENT_ERROR */);
7282
- if (this.shouldResolveImmediately(hl)) {
7626
+ if (this.shouldResolveImmediately(hl) && isV2(_window().grecaptcha)) {
7283
7627
  return Promise.resolve(_window().grecaptcha);
7284
7628
  }
7285
7629
  return new Promise((resolve, reject) => {
@@ -7290,7 +7634,7 @@ class ReCaptchaLoaderImpl {
7290
7634
  _window().clearTimeout(networkTimeout);
7291
7635
  delete _window()[_JSLOAD_CALLBACK];
7292
7636
  const recaptcha = _window().grecaptcha;
7293
- if (!recaptcha) {
7637
+ if (!recaptcha || !isV2(recaptcha)) {
7294
7638
  reject(_createError(auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */));
7295
7639
  return;
7296
7640
  }
@@ -9522,7 +9866,7 @@ function _isEmptyString(input) {
9522
9866
  }
9523
9867
 
9524
9868
  var name = "@firebase/auth";
9525
- var version = "0.22.0-canary.ea3849fff";
9869
+ var version = "0.22.0-canary.ecb4454c3";
9526
9870
 
9527
9871
  /**
9528
9872
  * @license
@@ -9746,5 +10090,5 @@ function getAuth(app = getApp()) {
9746
10090
  }
9747
10091
  registerAuth("Browser" /* ClientPlatform.BROWSER */);
9748
10092
 
9749
- export { linkWithCredential as $, ActionCodeOperation as A, deleteUser as B, debugErrorMap as C, prodErrorMap as D, AUTH_ERROR_CODES_MAP_DO_NOT_USE_INTERNALLY as E, FactorId as F, initializeAuth as G, connectAuthEmulator as H, AuthCredential as I, EmailAuthCredential as J, OAuthCredential as K, PhoneAuthCredential as L, inMemoryPersistence as M, EmailAuthProvider as N, OperationType as O, PhoneAuthProvider as P, FacebookAuthProvider as Q, RecaptchaVerifier as R, SignInMethod as S, TotpMultiFactorGenerator as T, GoogleAuthProvider as U, GithubAuthProvider as V, OAuthProvider as W, SAMLAuthProvider as X, TwitterAuthProvider as Y, signInAnonymously as Z, signInWithCredential as _, browserSessionPersistence as a, reauthenticateWithCredential as a0, signInWithCustomToken as a1, sendPasswordResetEmail as a2, confirmPasswordReset as a3, applyActionCode as a4, checkActionCode as a5, verifyPasswordResetCode as a6, createUserWithEmailAndPassword as a7, signInWithEmailAndPassword as a8, sendSignInLinkToEmail as a9, AuthEventManager as aA, _getInstance as aB, _persistenceKeyName as aC, _getRedirectResult as aD, _overrideRedirectResult as aE, _clearRedirectOutcomes as aF, _castAuth as aG, UserImpl as aH, AuthImpl as aI, _getClientVersion as aJ, _generateEventId as aK, AuthPopup as aL, FetchProvider as aM, SAMLAuthCredential as aN, isSignInWithEmailLink as aa, signInWithEmailLink as ab, fetchSignInMethodsForEmail as ac, sendEmailVerification as ad, verifyBeforeUpdateEmail as ae, ActionCodeURL as af, parseActionCodeURL as ag, updateProfile as ah, updateEmail as ai, updatePassword as aj, getIdToken as ak, getIdTokenResult as al, unlink as am, getAdditionalUserInfo as an, reload as ao, getMultiFactorResolver as ap, multiFactor as aq, debugAssert as ar, _isIOS as as, _isAndroid as at, _fail as au, _getRedirectUrl as av, _getProjectConfig as aw, _isIOS7Or8 as ax, _createError as ay, _assert as az, browserLocalPersistence as b, signInWithPopup as c, linkWithPopup as d, reauthenticateWithPopup as e, signInWithRedirect as f, linkWithRedirect as g, reauthenticateWithRedirect as h, indexedDBLocalPersistence as i, getRedirectResult as j, browserPopupRedirectResolver as k, linkWithPhoneNumber as l, PhoneMultiFactorGenerator as m, TotpSecret as n, getAuth as o, ProviderId as p, setPersistence as q, reauthenticateWithPhoneNumber as r, signInWithPhoneNumber as s, onIdTokenChanged as t, updatePhoneNumber as u, beforeAuthStateChanged as v, onAuthStateChanged as w, useDeviceLanguage as x, updateCurrentUser as y, signOut as z };
9750
- //# sourceMappingURL=index-5eca8e8e.js.map
10093
+ export { signInWithCredential as $, ActionCodeOperation as A, signOut as B, deleteUser as C, debugErrorMap as D, prodErrorMap as E, FactorId as F, AUTH_ERROR_CODES_MAP_DO_NOT_USE_INTERNALLY as G, initializeAuth as H, connectAuthEmulator as I, AuthCredential as J, EmailAuthCredential as K, OAuthCredential as L, PhoneAuthCredential as M, inMemoryPersistence as N, OperationType as O, PhoneAuthProvider as P, EmailAuthProvider as Q, RecaptchaVerifier as R, SignInMethod as S, TotpMultiFactorGenerator as T, FacebookAuthProvider as U, GoogleAuthProvider as V, GithubAuthProvider as W, OAuthProvider as X, SAMLAuthProvider as Y, TwitterAuthProvider as Z, signInAnonymously as _, browserSessionPersistence as a, linkWithCredential as a0, reauthenticateWithCredential as a1, signInWithCustomToken as a2, sendPasswordResetEmail as a3, confirmPasswordReset as a4, applyActionCode as a5, checkActionCode as a6, verifyPasswordResetCode as a7, createUserWithEmailAndPassword as a8, signInWithEmailAndPassword as a9, _assert as aA, AuthEventManager as aB, _getInstance as aC, _persistenceKeyName as aD, _getRedirectResult as aE, _overrideRedirectResult as aF, _clearRedirectOutcomes as aG, _castAuth as aH, UserImpl as aI, AuthImpl as aJ, _getClientVersion as aK, _generateEventId as aL, AuthPopup as aM, FetchProvider as aN, SAMLAuthCredential as aO, sendSignInLinkToEmail as aa, isSignInWithEmailLink as ab, signInWithEmailLink as ac, fetchSignInMethodsForEmail as ad, sendEmailVerification as ae, verifyBeforeUpdateEmail as af, ActionCodeURL as ag, parseActionCodeURL as ah, updateProfile as ai, updateEmail as aj, updatePassword as ak, getIdToken as al, getIdTokenResult as am, unlink as an, getAdditionalUserInfo as ao, reload as ap, getMultiFactorResolver as aq, multiFactor as ar, debugAssert as as, _isIOS as at, _isAndroid as au, _fail as av, _getRedirectUrl as aw, _getProjectConfig as ax, _isIOS7Or8 as ay, _createError as az, browserLocalPersistence as b, signInWithPopup as c, linkWithPopup as d, reauthenticateWithPopup as e, signInWithRedirect as f, linkWithRedirect as g, reauthenticateWithRedirect as h, indexedDBLocalPersistence as i, getRedirectResult as j, browserPopupRedirectResolver as k, linkWithPhoneNumber as l, PhoneMultiFactorGenerator as m, TotpSecret as n, getAuth as o, ProviderId as p, setPersistence as q, reauthenticateWithPhoneNumber as r, signInWithPhoneNumber as s, initializeRecaptchaConfig as t, updatePhoneNumber as u, onIdTokenChanged as v, beforeAuthStateChanged as w, onAuthStateChanged as x, useDeviceLanguage as y, updateCurrentUser as z };
10094
+ //# sourceMappingURL=index-2dbc6285.js.map