@firebase/auth 0.22.0 → 0.23.0-canary.0a27d2fbf

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 (209) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/auth-public.d.ts +57 -0
  3. package/dist/auth.d.ts +71 -1
  4. package/dist/browser-cjs/{index-5859881d.js → index-5df83e84.js} +590 -207
  5. package/dist/browser-cjs/index-5df83e84.js.map +1 -0
  6. package/dist/browser-cjs/index.js +3 -2
  7. package/dist/browser-cjs/index.js.map +1 -1
  8. package/dist/browser-cjs/internal.js +3 -2
  9. package/dist/browser-cjs/internal.js.map +1 -1
  10. package/dist/browser-cjs/src/api/authentication/email_and_password.d.ts +9 -0
  11. package/dist/browser-cjs/src/api/authentication/recaptcha.d.ts +16 -0
  12. package/dist/browser-cjs/src/api/authentication/sign_up.d.ts +4 -0
  13. package/dist/browser-cjs/src/api/errors.d.ts +9 -1
  14. package/dist/browser-cjs/src/api/index.d.ts +17 -2
  15. package/dist/browser-cjs/src/core/auth/auth_impl.d.ts +9 -1
  16. package/dist/browser-cjs/src/core/errors.d.ts +17 -1
  17. package/dist/browser-cjs/src/core/index.d.ts +26 -0
  18. package/dist/browser-cjs/src/core/util/handler.d.ts +1 -1
  19. package/dist/browser-cjs/src/core/util/log.d.ts +1 -0
  20. package/dist/browser-cjs/src/model/auth.d.ts +6 -0
  21. package/dist/browser-cjs/src/platform_browser/auth_window.d.ts +2 -2
  22. package/dist/browser-cjs/src/platform_browser/recaptcha/recaptcha.d.ts +33 -0
  23. package/dist/browser-cjs/src/platform_browser/recaptcha/recaptcha.test.d.ts +17 -0
  24. package/dist/browser-cjs/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +40 -0
  25. package/dist/browser-cjs/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.test.d.ts +17 -0
  26. package/dist/browser-cjs/src/platform_browser/recaptcha/recaptcha_mock.d.ts +16 -1
  27. package/dist/browser-cjs/src/platform_browser/strategies/popup.d.ts +1 -1
  28. package/dist/browser-cjs/test/helpers/api/helper.d.ts +2 -0
  29. package/dist/browser-cjs/test/helpers/mock_auth.d.ts +5 -0
  30. package/dist/cordova/index.js +2 -2
  31. package/dist/cordova/internal.js +21 -77
  32. package/dist/cordova/internal.js.map +1 -1
  33. package/dist/cordova/{popup_redirect-3519667a.js → popup_redirect-b3f8e40c.js} +778 -214
  34. package/dist/cordova/popup_redirect-b3f8e40c.js.map +1 -0
  35. package/dist/cordova/src/api/authentication/email_and_password.d.ts +9 -0
  36. package/dist/cordova/src/api/authentication/recaptcha.d.ts +16 -0
  37. package/dist/cordova/src/api/authentication/sign_up.d.ts +4 -0
  38. package/dist/cordova/src/api/errors.d.ts +9 -1
  39. package/dist/cordova/src/api/index.d.ts +17 -2
  40. package/dist/cordova/src/core/auth/auth_impl.d.ts +9 -1
  41. package/dist/cordova/src/core/errors.d.ts +17 -1
  42. package/dist/cordova/src/core/index.d.ts +26 -0
  43. package/dist/cordova/src/core/util/handler.d.ts +1 -1
  44. package/dist/cordova/src/core/util/log.d.ts +1 -0
  45. package/dist/cordova/src/model/auth.d.ts +6 -0
  46. package/dist/cordova/src/platform_browser/auth_window.d.ts +2 -2
  47. package/dist/cordova/src/platform_browser/recaptcha/recaptcha.d.ts +33 -0
  48. package/dist/cordova/src/platform_browser/recaptcha/recaptcha.test.d.ts +17 -0
  49. package/dist/cordova/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +40 -0
  50. package/dist/cordova/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.test.d.ts +17 -0
  51. package/dist/cordova/src/platform_browser/recaptcha/recaptcha_mock.d.ts +16 -1
  52. package/dist/cordova/src/platform_browser/strategies/popup.d.ts +1 -1
  53. package/dist/cordova/test/helpers/api/helper.d.ts +2 -0
  54. package/dist/cordova/test/helpers/mock_auth.d.ts +5 -0
  55. package/dist/esm2017/{index-680e2b70.js → index-6cb4f120.js} +591 -209
  56. package/dist/esm2017/index-6cb4f120.js.map +1 -0
  57. package/dist/esm2017/index.js +2 -2
  58. package/dist/esm2017/internal.js +3 -3
  59. package/dist/esm2017/src/api/authentication/email_and_password.d.ts +9 -0
  60. package/dist/esm2017/src/api/authentication/recaptcha.d.ts +16 -0
  61. package/dist/esm2017/src/api/authentication/sign_up.d.ts +4 -0
  62. package/dist/esm2017/src/api/errors.d.ts +9 -1
  63. package/dist/esm2017/src/api/index.d.ts +17 -2
  64. package/dist/esm2017/src/core/auth/auth_impl.d.ts +9 -1
  65. package/dist/esm2017/src/core/errors.d.ts +17 -1
  66. package/dist/esm2017/src/core/index.d.ts +26 -0
  67. package/dist/esm2017/src/core/util/handler.d.ts +1 -1
  68. package/dist/esm2017/src/core/util/log.d.ts +1 -0
  69. package/dist/esm2017/src/model/auth.d.ts +6 -0
  70. package/dist/esm2017/src/platform_browser/auth_window.d.ts +2 -2
  71. package/dist/esm2017/src/platform_browser/recaptcha/recaptcha.d.ts +33 -0
  72. package/dist/esm2017/src/platform_browser/recaptcha/recaptcha.test.d.ts +17 -0
  73. package/dist/esm2017/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +40 -0
  74. package/dist/esm2017/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.test.d.ts +17 -0
  75. package/dist/esm2017/src/platform_browser/recaptcha/recaptcha_mock.d.ts +16 -1
  76. package/dist/esm2017/src/platform_browser/strategies/popup.d.ts +1 -1
  77. package/dist/esm2017/test/helpers/api/helper.d.ts +2 -0
  78. package/dist/esm2017/test/helpers/mock_auth.d.ts +5 -0
  79. package/dist/esm5/{index-714e827f.js → index-4dc6213a.js} +797 -289
  80. package/dist/esm5/index-4dc6213a.js.map +1 -0
  81. package/dist/esm5/index.js +1 -1
  82. package/dist/esm5/internal.js +2 -2
  83. package/dist/esm5/src/api/authentication/email_and_password.d.ts +9 -0
  84. package/dist/esm5/src/api/authentication/recaptcha.d.ts +16 -0
  85. package/dist/esm5/src/api/authentication/sign_up.d.ts +4 -0
  86. package/dist/esm5/src/api/errors.d.ts +9 -1
  87. package/dist/esm5/src/api/index.d.ts +17 -2
  88. package/dist/esm5/src/core/auth/auth_impl.d.ts +9 -1
  89. package/dist/esm5/src/core/errors.d.ts +17 -1
  90. package/dist/esm5/src/core/index.d.ts +26 -0
  91. package/dist/esm5/src/core/util/handler.d.ts +1 -1
  92. package/dist/esm5/src/core/util/log.d.ts +1 -0
  93. package/dist/esm5/src/model/auth.d.ts +6 -0
  94. package/dist/esm5/src/platform_browser/auth_window.d.ts +2 -2
  95. package/dist/esm5/src/platform_browser/recaptcha/recaptcha.d.ts +33 -0
  96. package/dist/esm5/src/platform_browser/recaptcha/recaptcha.test.d.ts +17 -0
  97. package/dist/esm5/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +40 -0
  98. package/dist/esm5/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.test.d.ts +17 -0
  99. package/dist/esm5/src/platform_browser/recaptcha/recaptcha_mock.d.ts +16 -1
  100. package/dist/esm5/src/platform_browser/strategies/popup.d.ts +1 -1
  101. package/dist/esm5/test/helpers/api/helper.d.ts +2 -0
  102. package/dist/esm5/test/helpers/mock_auth.d.ts +5 -0
  103. package/dist/index.webworker.esm5.js +602 -74
  104. package/dist/index.webworker.esm5.js.map +1 -1
  105. package/dist/node/index.js +2 -1
  106. package/dist/node/index.js.map +1 -1
  107. package/dist/node/internal.js +62 -42
  108. package/dist/node/internal.js.map +1 -1
  109. package/dist/node/src/api/authentication/email_and_password.d.ts +9 -0
  110. package/dist/node/src/api/authentication/recaptcha.d.ts +16 -0
  111. package/dist/node/src/api/authentication/sign_up.d.ts +4 -0
  112. package/dist/node/src/api/errors.d.ts +9 -1
  113. package/dist/node/src/api/index.d.ts +17 -2
  114. package/dist/node/src/core/auth/auth_impl.d.ts +9 -1
  115. package/dist/node/src/core/errors.d.ts +17 -1
  116. package/dist/node/src/core/index.d.ts +26 -0
  117. package/dist/node/src/core/util/handler.d.ts +1 -1
  118. package/dist/node/src/core/util/log.d.ts +1 -0
  119. package/dist/node/src/model/auth.d.ts +6 -0
  120. package/dist/node/src/platform_browser/auth_window.d.ts +2 -2
  121. package/dist/node/src/platform_browser/recaptcha/recaptcha.d.ts +33 -0
  122. package/dist/node/src/platform_browser/recaptcha/recaptcha.test.d.ts +17 -0
  123. package/dist/node/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +40 -0
  124. package/dist/node/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.test.d.ts +17 -0
  125. package/dist/node/src/platform_browser/recaptcha/recaptcha_mock.d.ts +16 -1
  126. package/dist/node/src/platform_browser/strategies/popup.d.ts +1 -1
  127. package/dist/node/test/helpers/api/helper.d.ts +2 -0
  128. package/dist/node/test/helpers/mock_auth.d.ts +5 -0
  129. package/dist/node/{totp-416a2adc.js → totp-c1b55906.js} +700 -171
  130. package/dist/node/totp-c1b55906.js.map +1 -0
  131. package/dist/node-esm/index.js +1 -1
  132. package/dist/node-esm/internal.js +16 -4
  133. package/dist/node-esm/internal.js.map +1 -1
  134. package/dist/node-esm/src/api/authentication/email_and_password.d.ts +9 -0
  135. package/dist/node-esm/src/api/authentication/recaptcha.d.ts +16 -0
  136. package/dist/node-esm/src/api/authentication/sign_up.d.ts +4 -0
  137. package/dist/node-esm/src/api/errors.d.ts +9 -1
  138. package/dist/node-esm/src/api/index.d.ts +17 -2
  139. package/dist/node-esm/src/core/auth/auth_impl.d.ts +9 -1
  140. package/dist/node-esm/src/core/errors.d.ts +17 -1
  141. package/dist/node-esm/src/core/index.d.ts +26 -0
  142. package/dist/node-esm/src/core/util/handler.d.ts +1 -1
  143. package/dist/node-esm/src/core/util/log.d.ts +1 -0
  144. package/dist/node-esm/src/model/auth.d.ts +6 -0
  145. package/dist/node-esm/src/platform_browser/auth_window.d.ts +2 -2
  146. package/dist/node-esm/src/platform_browser/recaptcha/recaptcha.d.ts +33 -0
  147. package/dist/node-esm/src/platform_browser/recaptcha/recaptcha.test.d.ts +17 -0
  148. package/dist/node-esm/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +40 -0
  149. package/dist/node-esm/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.test.d.ts +17 -0
  150. package/dist/node-esm/src/platform_browser/recaptcha/recaptcha_mock.d.ts +16 -1
  151. package/dist/node-esm/src/platform_browser/strategies/popup.d.ts +1 -1
  152. package/dist/node-esm/test/helpers/api/helper.d.ts +2 -0
  153. package/dist/node-esm/test/helpers/mock_auth.d.ts +5 -0
  154. package/dist/node-esm/{totp-c3bf2a20.js → totp-5cad7b9f.js} +557 -140
  155. package/dist/node-esm/totp-5cad7b9f.js.map +1 -0
  156. package/dist/rn/index.js +2 -1
  157. package/dist/rn/index.js.map +1 -1
  158. package/dist/rn/internal.js +79 -48
  159. package/dist/rn/internal.js.map +1 -1
  160. package/dist/rn/{phone-2ec1815d.js → phone-5059d9ba.js} +738 -259
  161. package/dist/rn/phone-5059d9ba.js.map +1 -0
  162. package/dist/rn/src/api/authentication/email_and_password.d.ts +9 -0
  163. package/dist/rn/src/api/authentication/recaptcha.d.ts +16 -0
  164. package/dist/rn/src/api/authentication/sign_up.d.ts +4 -0
  165. package/dist/rn/src/api/errors.d.ts +9 -1
  166. package/dist/rn/src/api/index.d.ts +17 -2
  167. package/dist/rn/src/core/auth/auth_impl.d.ts +9 -1
  168. package/dist/rn/src/core/errors.d.ts +17 -1
  169. package/dist/rn/src/core/index.d.ts +26 -0
  170. package/dist/rn/src/core/util/handler.d.ts +1 -1
  171. package/dist/rn/src/core/util/log.d.ts +1 -0
  172. package/dist/rn/src/model/auth.d.ts +6 -0
  173. package/dist/rn/src/platform_browser/auth_window.d.ts +2 -2
  174. package/dist/rn/src/platform_browser/recaptcha/recaptcha.d.ts +33 -0
  175. package/dist/rn/src/platform_browser/recaptcha/recaptcha.test.d.ts +17 -0
  176. package/dist/rn/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +40 -0
  177. package/dist/rn/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.test.d.ts +17 -0
  178. package/dist/rn/src/platform_browser/recaptcha/recaptcha_mock.d.ts +16 -1
  179. package/dist/rn/src/platform_browser/strategies/popup.d.ts +1 -1
  180. package/dist/rn/test/helpers/api/helper.d.ts +2 -0
  181. package/dist/rn/test/helpers/mock_auth.d.ts +5 -0
  182. package/dist/src/api/authentication/email_and_password.d.ts +9 -0
  183. package/dist/src/api/authentication/recaptcha.d.ts +16 -0
  184. package/dist/src/api/authentication/sign_up.d.ts +4 -0
  185. package/dist/src/api/errors.d.ts +9 -1
  186. package/dist/src/api/index.d.ts +17 -2
  187. package/dist/src/core/auth/auth_impl.d.ts +9 -1
  188. package/dist/src/core/errors.d.ts +17 -1
  189. package/dist/src/core/index.d.ts +26 -0
  190. package/dist/src/core/util/handler.d.ts +1 -1
  191. package/dist/src/core/util/log.d.ts +1 -0
  192. package/dist/src/model/auth.d.ts +6 -0
  193. package/dist/src/platform_browser/auth_window.d.ts +2 -2
  194. package/dist/src/platform_browser/recaptcha/recaptcha.d.ts +33 -0
  195. package/dist/src/platform_browser/recaptcha/recaptcha.test.d.ts +17 -0
  196. package/dist/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +40 -0
  197. package/dist/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.test.d.ts +17 -0
  198. package/dist/src/platform_browser/recaptcha/recaptcha_mock.d.ts +16 -1
  199. package/dist/src/platform_browser/strategies/popup.d.ts +1 -1
  200. package/dist/test/helpers/api/helper.d.ts +2 -0
  201. package/dist/test/helpers/mock_auth.d.ts +5 -0
  202. package/package.json +6 -6
  203. package/dist/browser-cjs/index-5859881d.js.map +0 -1
  204. package/dist/cordova/popup_redirect-3519667a.js.map +0 -1
  205. package/dist/esm2017/index-680e2b70.js.map +0 -1
  206. package/dist/esm5/index-714e827f.js.map +0 -1
  207. package/dist/node/totp-416a2adc.js.map +0 -1
  208. package/dist/node-esm/totp-c3bf2a20.js.map +0 -1
  209. package/dist/rn/phone-2ec1815d.js.map +0 -1
@@ -290,6 +290,14 @@ function _debugErrorMap() {
290
290
  'different options. To avoid this error, call initializeAuth() with the ' +
291
291
  'same options as when it was originally called, or call getAuth() to return the' +
292
292
  ' already initialized instance.',
293
+ _a["missing-recaptcha-token" /* AuthErrorCode.MISSING_RECAPTCHA_TOKEN */] = 'The reCAPTCHA token is missing when sending request to the backend.',
294
+ _a["invalid-recaptcha-token" /* AuthErrorCode.INVALID_RECAPTCHA_TOKEN */] = 'The reCAPTCHA token is invalid when sending request to the backend.',
295
+ _a["invalid-recaptcha-action" /* AuthErrorCode.INVALID_RECAPTCHA_ACTION */] = 'The reCAPTCHA action is invalid when sending request to the backend.',
296
+ _a["recaptcha-not-enabled" /* AuthErrorCode.RECAPTCHA_NOT_ENABLED */] = 'reCAPTCHA Enterprise integration is not enabled for this project.',
297
+ _a["missing-client-type" /* AuthErrorCode.MISSING_CLIENT_TYPE */] = 'The reCAPTCHA client type is missing when sending request to the backend.',
298
+ _a["missing-recaptcha-version" /* AuthErrorCode.MISSING_RECAPTCHA_VERSION */] = 'The reCAPTCHA version is missing when sending request to the backend.',
299
+ _a["invalid-req-type" /* AuthErrorCode.INVALID_REQ_TYPE */] = 'Invalid request parameters.',
300
+ _a["invalid-recaptcha-version" /* AuthErrorCode.INVALID_RECAPTCHA_VERSION */] = 'The reCAPTCHA version is invalid when sending request to the backend.',
293
301
  _a;
294
302
  }
295
303
  function _prodErrorMap() {
@@ -426,7 +434,15 @@ var AUTH_ERROR_CODES_MAP_DO_NOT_USE_INTERNALLY = {
426
434
  USER_SIGNED_OUT: 'auth/user-signed-out',
427
435
  WEAK_PASSWORD: 'auth/weak-password',
428
436
  WEB_STORAGE_UNSUPPORTED: 'auth/web-storage-unsupported',
429
- ALREADY_INITIALIZED: 'auth/already-initialized'
437
+ ALREADY_INITIALIZED: 'auth/already-initialized',
438
+ RECAPTCHA_NOT_ENABLED: 'auth/recaptcha-not-enabled',
439
+ MISSING_RECAPTCHA_TOKEN: 'auth/missing-recaptcha-token',
440
+ INVALID_RECAPTCHA_TOKEN: 'auth/invalid-recaptcha-token',
441
+ INVALID_RECAPTCHA_ACTION: 'auth/invalid-recaptcha-action',
442
+ MISSING_CLIENT_TYPE: 'auth/missing-client-type',
443
+ MISSING_RECAPTCHA_VERSION: 'auth/missing-recaptcha-version',
444
+ INVALID_RECAPTCHA_VERSION: 'auth/invalid-recaptcha-version',
445
+ INVALID_REQ_TYPE: 'auth/invalid-req-type'
430
446
  };
431
447
 
432
448
  /**
@@ -446,6 +462,15 @@ var AUTH_ERROR_CODES_MAP_DO_NOT_USE_INTERNALLY = {
446
462
  * limitations under the License.
447
463
  */
448
464
  var logClient = new logger.Logger('@firebase/auth');
465
+ function _logWarn(msg) {
466
+ var args = [];
467
+ for (var _i = 1; _i < arguments.length; _i++) {
468
+ args[_i - 1] = arguments[_i];
469
+ }
470
+ if (logClient.logLevel <= logger.LogLevel.WARN) {
471
+ logClient.warn.apply(logClient, tslib.__spreadArray(["Auth (".concat(app.SDK_VERSION, "): ").concat(msg)], args, false));
472
+ }
473
+ }
449
474
  function _logError(msg) {
450
475
  var args = [];
451
476
  for (var _i = 1; _i < arguments.length; _i++) {
@@ -548,103 +573,6 @@ function debugAssert(assertion, message) {
548
573
  }
549
574
  }
550
575
 
551
- /**
552
- * @license
553
- * Copyright 2020 Google LLC
554
- *
555
- * Licensed under the Apache License, Version 2.0 (the "License");
556
- * you may not use this file except in compliance with the License.
557
- * You may obtain a copy of the License at
558
- *
559
- * http://www.apache.org/licenses/LICENSE-2.0
560
- *
561
- * Unless required by applicable law or agreed to in writing, software
562
- * distributed under the License is distributed on an "AS IS" BASIS,
563
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
564
- * See the License for the specific language governing permissions and
565
- * limitations under the License.
566
- */
567
- var instanceCache = new Map();
568
- function _getInstance(cls) {
569
- debugAssert(cls instanceof Function, 'Expected a class definition');
570
- var instance = instanceCache.get(cls);
571
- if (instance) {
572
- debugAssert(instance instanceof cls, 'Instance stored in cache mismatched with class');
573
- return instance;
574
- }
575
- instance = new cls();
576
- instanceCache.set(cls, instance);
577
- return instance;
578
- }
579
-
580
- /**
581
- * @license
582
- * Copyright 2020 Google LLC
583
- *
584
- * Licensed under the Apache License, Version 2.0 (the "License");
585
- * you may not use this file except in compliance with the License.
586
- * You may obtain a copy of the License at
587
- *
588
- * http://www.apache.org/licenses/LICENSE-2.0
589
- *
590
- * Unless required by applicable law or agreed to in writing, software
591
- * distributed under the License is distributed on an "AS IS" BASIS,
592
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
593
- * See the License for the specific language governing permissions and
594
- * limitations under the License.
595
- */
596
- /**
597
- * Initializes an {@link Auth} instance with fine-grained control over
598
- * {@link Dependencies}.
599
- *
600
- * @remarks
601
- *
602
- * This function allows more control over the {@link Auth} instance than
603
- * {@link getAuth}. `getAuth` uses platform-specific defaults to supply
604
- * the {@link Dependencies}. In general, `getAuth` is the easiest way to
605
- * initialize Auth and works for most use cases. Use `initializeAuth` if you
606
- * need control over which persistence layer is used, or to minimize bundle
607
- * size if you're not using either `signInWithPopup` or `signInWithRedirect`.
608
- *
609
- * For example, if your app only uses anonymous accounts and you only want
610
- * accounts saved for the current session, initialize `Auth` with:
611
- *
612
- * ```js
613
- * const auth = initializeAuth(app, {
614
- * persistence: browserSessionPersistence,
615
- * popupRedirectResolver: undefined,
616
- * });
617
- * ```
618
- *
619
- * @public
620
- */
621
- function initializeAuth(app$1, deps) {
622
- var provider = app._getProvider(app$1, 'auth');
623
- if (provider.isInitialized()) {
624
- var auth_1 = provider.getImmediate();
625
- var initialOptions = provider.getOptions();
626
- if (util.deepEqual(initialOptions, deps !== null && deps !== void 0 ? deps : {})) {
627
- return auth_1;
628
- }
629
- else {
630
- _fail(auth_1, "already-initialized" /* AuthErrorCode.ALREADY_INITIALIZED */);
631
- }
632
- }
633
- var auth = provider.initialize({ options: deps });
634
- return auth;
635
- }
636
- function _initializeAuthInstance(auth, deps) {
637
- var persistence = (deps === null || deps === void 0 ? void 0 : deps.persistence) || [];
638
- var hierarchy = (Array.isArray(persistence) ? persistence : [persistence]).map(_getInstance);
639
- if (deps === null || deps === void 0 ? void 0 : deps.errorMap) {
640
- auth._updateErrorMap(deps.errorMap);
641
- }
642
- // This promise is intended to float; auth initialization happens in the
643
- // background, meanwhile the auth object may be used by the app.
644
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
645
- auth._initializeWithPersistence(hierarchy, deps === null || deps === void 0 ? void 0 : deps.popupRedirectResolver);
646
- }
647
-
648
576
  /**
649
577
  * @license
650
578
  * Copyright 2020 Google LLC
@@ -929,6 +857,15 @@ var SERVER_ERROR_MAP = (_a$1 = {},
929
857
  _a$1["SECOND_FACTOR_LIMIT_EXCEEDED" /* ServerError.SECOND_FACTOR_LIMIT_EXCEEDED */] = "maximum-second-factor-count-exceeded" /* AuthErrorCode.SECOND_FACTOR_LIMIT_EXCEEDED */,
930
858
  // Blocking functions related errors.
931
859
  _a$1["BLOCKING_FUNCTION_ERROR_RESPONSE" /* ServerError.BLOCKING_FUNCTION_ERROR_RESPONSE */] = "internal-error" /* AuthErrorCode.INTERNAL_ERROR */,
860
+ // Recaptcha related errors.
861
+ _a$1["RECAPTCHA_NOT_ENABLED" /* ServerError.RECAPTCHA_NOT_ENABLED */] = "recaptcha-not-enabled" /* AuthErrorCode.RECAPTCHA_NOT_ENABLED */,
862
+ _a$1["MISSING_RECAPTCHA_TOKEN" /* ServerError.MISSING_RECAPTCHA_TOKEN */] = "missing-recaptcha-token" /* AuthErrorCode.MISSING_RECAPTCHA_TOKEN */,
863
+ _a$1["INVALID_RECAPTCHA_TOKEN" /* ServerError.INVALID_RECAPTCHA_TOKEN */] = "invalid-recaptcha-token" /* AuthErrorCode.INVALID_RECAPTCHA_TOKEN */,
864
+ _a$1["INVALID_RECAPTCHA_ACTION" /* ServerError.INVALID_RECAPTCHA_ACTION */] = "invalid-recaptcha-action" /* AuthErrorCode.INVALID_RECAPTCHA_ACTION */,
865
+ _a$1["MISSING_CLIENT_TYPE" /* ServerError.MISSING_CLIENT_TYPE */] = "missing-client-type" /* AuthErrorCode.MISSING_CLIENT_TYPE */,
866
+ _a$1["MISSING_RECAPTCHA_VERSION" /* ServerError.MISSING_RECAPTCHA_VERSION */] = "missing-recaptcha-version" /* AuthErrorCode.MISSING_RECAPTCHA_VERSION */,
867
+ _a$1["INVALID_RECAPTCHA_VERSION" /* ServerError.INVALID_RECAPTCHA_VERSION */] = "invalid-recaptcha-version" /* AuthErrorCode.INVALID_RECAPTCHA_VERSION */,
868
+ _a$1["INVALID_REQ_TYPE" /* ServerError.INVALID_REQ_TYPE */] = "invalid-req-type" /* AuthErrorCode.INVALID_REQ_TYPE */,
932
869
  _a$1);
933
870
 
934
871
  /**
@@ -2050,6 +1987,35 @@ var UserImpl = /** @class */ (function () {
2050
1987
  return UserImpl;
2051
1988
  }());
2052
1989
 
1990
+ /**
1991
+ * @license
1992
+ * Copyright 2020 Google LLC
1993
+ *
1994
+ * Licensed under the Apache License, Version 2.0 (the "License");
1995
+ * you may not use this file except in compliance with the License.
1996
+ * You may obtain a copy of the License at
1997
+ *
1998
+ * http://www.apache.org/licenses/LICENSE-2.0
1999
+ *
2000
+ * Unless required by applicable law or agreed to in writing, software
2001
+ * distributed under the License is distributed on an "AS IS" BASIS,
2002
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2003
+ * See the License for the specific language governing permissions and
2004
+ * limitations under the License.
2005
+ */
2006
+ var instanceCache = new Map();
2007
+ function _getInstance(cls) {
2008
+ debugAssert(cls instanceof Function, 'Expected a class definition');
2009
+ var instance = instanceCache.get(cls);
2010
+ if (instance) {
2011
+ debugAssert(instance instanceof cls, 'Instance stored in cache mismatched with class');
2012
+ return instance;
2013
+ }
2014
+ instance = new cls();
2015
+ instanceCache.set(cls, instance);
2016
+ return instance;
2017
+ }
2018
+
2053
2019
  /**
2054
2020
  * @license
2055
2021
  * Copyright 2019 Google LLC
@@ -2483,6 +2449,271 @@ function _getClientVersion(clientPlatform, frameworks) {
2483
2449
  return "".concat(reportedPlatform, "/").concat("JsCore" /* ClientImplementation.CORE */, "/").concat(app.SDK_VERSION, "/").concat(reportedFrameworks);
2484
2450
  }
2485
2451
 
2452
+ /**
2453
+ * @license
2454
+ * Copyright 2020 Google LLC
2455
+ *
2456
+ * Licensed under the Apache License, Version 2.0 (the "License");
2457
+ * you may not use this file except in compliance with the License.
2458
+ * You may obtain a copy of the License at
2459
+ *
2460
+ * http://www.apache.org/licenses/LICENSE-2.0
2461
+ *
2462
+ * Unless required by applicable law or agreed to in writing, software
2463
+ * distributed under the License is distributed on an "AS IS" BASIS,
2464
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2465
+ * See the License for the specific language governing permissions and
2466
+ * limitations under the License.
2467
+ */
2468
+ function getRecaptchaConfig(auth, request) {
2469
+ return tslib.__awaiter(this, void 0, void 0, function () {
2470
+ return tslib.__generator(this, function (_a) {
2471
+ return [2 /*return*/, _performApiRequest(auth, "GET" /* HttpMethod.GET */, "/v2/recaptchaConfig" /* Endpoint.GET_RECAPTCHA_CONFIG */, _addTidIfNecessary(auth, request))];
2472
+ });
2473
+ });
2474
+ }
2475
+
2476
+ /**
2477
+ * @license
2478
+ * Copyright 2020 Google LLC
2479
+ *
2480
+ * Licensed under the Apache License, Version 2.0 (the "License");
2481
+ * you may not use this file except in compliance with the License.
2482
+ * You may obtain a copy of the License at
2483
+ *
2484
+ * http://www.apache.org/licenses/LICENSE-2.0
2485
+ *
2486
+ * Unless required by applicable law or agreed to in writing, software
2487
+ * distributed under the License is distributed on an "AS IS" BASIS,
2488
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2489
+ * See the License for the specific language governing permissions and
2490
+ * limitations under the License.
2491
+ */
2492
+ function isEnterprise(grecaptcha) {
2493
+ return (grecaptcha !== undefined &&
2494
+ grecaptcha.enterprise !== undefined);
2495
+ }
2496
+ var RecaptchaConfig = /** @class */ (function () {
2497
+ function RecaptchaConfig(response) {
2498
+ /**
2499
+ * The reCAPTCHA site key.
2500
+ */
2501
+ this.siteKey = '';
2502
+ /**
2503
+ * The reCAPTCHA enablement status of the {@link EmailAuthProvider} for the current tenant.
2504
+ */
2505
+ this.emailPasswordEnabled = false;
2506
+ if (response.recaptchaKey === undefined) {
2507
+ throw new Error('recaptchaKey undefined');
2508
+ }
2509
+ // Example response.recaptchaKey: "projects/proj123/keys/sitekey123"
2510
+ this.siteKey = response.recaptchaKey.split('/')[3];
2511
+ this.emailPasswordEnabled = response.recaptchaEnforcementState.some(function (enforcementState) {
2512
+ return enforcementState.provider === 'EMAIL_PASSWORD_PROVIDER' &&
2513
+ enforcementState.enforcementState !== 'OFF';
2514
+ });
2515
+ }
2516
+ return RecaptchaConfig;
2517
+ }());
2518
+
2519
+ /**
2520
+ * @license
2521
+ * Copyright 2020 Google LLC
2522
+ *
2523
+ * Licensed under the Apache License, Version 2.0 (the "License");
2524
+ * you may not use this file except in compliance with the License.
2525
+ * You may obtain a copy of the License at
2526
+ *
2527
+ * http://www.apache.org/licenses/LICENSE-2.0
2528
+ *
2529
+ * Unless required by applicable law or agreed to in writing, software
2530
+ * distributed under the License is distributed on an "AS IS" BASIS,
2531
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2532
+ * See the License for the specific language governing permissions and
2533
+ * limitations under the License.
2534
+ */
2535
+ function getScriptParentElement() {
2536
+ var _a, _b;
2537
+ return (_b = (_a = document.getElementsByTagName('head')) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : document;
2538
+ }
2539
+ function _loadJS(url) {
2540
+ // TODO: consider adding timeout support & cancellation
2541
+ return new Promise(function (resolve, reject) {
2542
+ var el = document.createElement('script');
2543
+ el.setAttribute('src', url);
2544
+ el.onload = resolve;
2545
+ el.onerror = function (e) {
2546
+ var error = _createError("internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
2547
+ error.customData = e;
2548
+ reject(error);
2549
+ };
2550
+ el.type = 'text/javascript';
2551
+ el.charset = 'UTF-8';
2552
+ getScriptParentElement().appendChild(el);
2553
+ });
2554
+ }
2555
+
2556
+ /* eslint-disable @typescript-eslint/no-require-imports */
2557
+ var RECAPTCHA_ENTERPRISE_URL = 'https://www.google.com/recaptcha/enterprise.js?render=';
2558
+ var RECAPTCHA_ENTERPRISE_VERIFIER_TYPE = 'recaptcha-enterprise';
2559
+ var RecaptchaEnterpriseVerifier = /** @class */ (function () {
2560
+ /**
2561
+ *
2562
+ * @param authExtern - The corresponding Firebase {@link Auth} instance.
2563
+ *
2564
+ */
2565
+ function RecaptchaEnterpriseVerifier(authExtern) {
2566
+ /**
2567
+ * Identifies the type of application verifier (e.g. "recaptcha-enterprise").
2568
+ */
2569
+ this.type = RECAPTCHA_ENTERPRISE_VERIFIER_TYPE;
2570
+ this.auth = _castAuth(authExtern);
2571
+ }
2572
+ /**
2573
+ * Executes the verification process.
2574
+ *
2575
+ * @returns A Promise for a token that can be used to assert the validity of a request.
2576
+ */
2577
+ RecaptchaEnterpriseVerifier.prototype.verify = function (action, forceRefresh) {
2578
+ if (action === void 0) { action = 'verify'; }
2579
+ if (forceRefresh === void 0) { forceRefresh = false; }
2580
+ return tslib.__awaiter(this, void 0, void 0, function () {
2581
+ function retrieveSiteKey(auth) {
2582
+ return tslib.__awaiter(this, void 0, void 0, function () {
2583
+ var _this = this;
2584
+ return tslib.__generator(this, function (_a) {
2585
+ if (!forceRefresh) {
2586
+ if (auth.tenantId == null && auth._agentRecaptchaConfig != null) {
2587
+ return [2 /*return*/, auth._agentRecaptchaConfig.siteKey];
2588
+ }
2589
+ if (auth.tenantId != null &&
2590
+ auth._tenantRecaptchaConfigs[auth.tenantId] !== undefined) {
2591
+ return [2 /*return*/, auth._tenantRecaptchaConfigs[auth.tenantId].siteKey];
2592
+ }
2593
+ }
2594
+ return [2 /*return*/, new Promise(function (resolve, reject) { return tslib.__awaiter(_this, void 0, void 0, function () {
2595
+ return tslib.__generator(this, function (_a) {
2596
+ getRecaptchaConfig(auth, {
2597
+ clientType: "CLIENT_TYPE_WEB" /* RecaptchaClientType.WEB */,
2598
+ version: "RECAPTCHA_ENTERPRISE" /* RecaptchaVersion.ENTERPRISE */
2599
+ })
2600
+ .then(function (response) {
2601
+ if (response.recaptchaKey === undefined) {
2602
+ reject(new Error('recaptcha Enterprise site key undefined'));
2603
+ }
2604
+ else {
2605
+ var config = new RecaptchaConfig(response);
2606
+ if (auth.tenantId == null) {
2607
+ auth._agentRecaptchaConfig = config;
2608
+ }
2609
+ else {
2610
+ auth._tenantRecaptchaConfigs[auth.tenantId] = config;
2611
+ }
2612
+ return resolve(config.siteKey);
2613
+ }
2614
+ })
2615
+ .catch(function (error) {
2616
+ reject(error);
2617
+ });
2618
+ return [2 /*return*/];
2619
+ });
2620
+ }); })];
2621
+ });
2622
+ });
2623
+ }
2624
+ function retrieveRecaptchaToken(siteKey, resolve, reject) {
2625
+ var grecaptcha = window.grecaptcha;
2626
+ if (isEnterprise(grecaptcha)) {
2627
+ grecaptcha.enterprise.ready(function () {
2628
+ try {
2629
+ grecaptcha.enterprise
2630
+ .execute(siteKey, { action: action })
2631
+ .then(function (token) {
2632
+ resolve(token);
2633
+ })
2634
+ .catch(function (error) {
2635
+ reject(error);
2636
+ });
2637
+ }
2638
+ catch (error) {
2639
+ reject(error);
2640
+ }
2641
+ });
2642
+ }
2643
+ else {
2644
+ reject(Error('No reCAPTCHA enterprise script loaded.'));
2645
+ }
2646
+ }
2647
+ var _this = this;
2648
+ return tslib.__generator(this, function (_a) {
2649
+ return [2 /*return*/, new Promise(function (resolve, reject) {
2650
+ retrieveSiteKey(_this.auth)
2651
+ .then(function (siteKey) {
2652
+ if (!forceRefresh && isEnterprise(window.grecaptcha)) {
2653
+ retrieveRecaptchaToken(siteKey, resolve, reject);
2654
+ }
2655
+ else {
2656
+ if (typeof window === 'undefined') {
2657
+ reject(new Error('RecaptchaVerifier is only supported in browser'));
2658
+ return;
2659
+ }
2660
+ _loadJS(RECAPTCHA_ENTERPRISE_URL + siteKey)
2661
+ .then(function () {
2662
+ retrieveRecaptchaToken(siteKey, resolve, reject);
2663
+ })
2664
+ .catch(function (error) {
2665
+ reject(error);
2666
+ });
2667
+ }
2668
+ })
2669
+ .catch(function (error) {
2670
+ reject(error);
2671
+ });
2672
+ })];
2673
+ });
2674
+ });
2675
+ };
2676
+ return RecaptchaEnterpriseVerifier;
2677
+ }());
2678
+ function injectRecaptchaFields(auth, request, action, captchaResp) {
2679
+ if (captchaResp === void 0) { captchaResp = false; }
2680
+ return tslib.__awaiter(this, void 0, void 0, function () {
2681
+ var verifier, captchaResponse, newRequest;
2682
+ return tslib.__generator(this, function (_a) {
2683
+ switch (_a.label) {
2684
+ case 0:
2685
+ verifier = new RecaptchaEnterpriseVerifier(auth);
2686
+ _a.label = 1;
2687
+ case 1:
2688
+ _a.trys.push([1, 3, , 5]);
2689
+ return [4 /*yield*/, verifier.verify(action)];
2690
+ case 2:
2691
+ captchaResponse = _a.sent();
2692
+ return [3 /*break*/, 5];
2693
+ case 3:
2694
+ _a.sent();
2695
+ return [4 /*yield*/, verifier.verify(action, true)];
2696
+ case 4:
2697
+ captchaResponse = _a.sent();
2698
+ return [3 /*break*/, 5];
2699
+ case 5:
2700
+ newRequest = tslib.__assign({}, request);
2701
+ if (!captchaResp) {
2702
+ Object.assign(newRequest, { captchaResponse: captchaResponse });
2703
+ }
2704
+ else {
2705
+ Object.assign(newRequest, { 'captchaResp': captchaResponse });
2706
+ }
2707
+ Object.assign(newRequest, { 'clientType': "CLIENT_TYPE_WEB" /* RecaptchaClientType.WEB */ });
2708
+ Object.assign(newRequest, {
2709
+ 'recaptchaVersion': "RECAPTCHA_ENTERPRISE" /* RecaptchaVersion.ENTERPRISE */
2710
+ });
2711
+ return [2 /*return*/, newRequest];
2712
+ }
2713
+ });
2714
+ });
2715
+ }
2716
+
2486
2717
  /**
2487
2718
  * @license
2488
2719
  * Copyright 2022 Google LLC
@@ -2604,9 +2835,10 @@ var AuthMiddlewareQueue = /** @class */ (function () {
2604
2835
  * limitations under the License.
2605
2836
  */
2606
2837
  var AuthImpl = /** @class */ (function () {
2607
- function AuthImpl(app, heartbeatServiceProvider, config) {
2838
+ function AuthImpl(app, heartbeatServiceProvider, appCheckServiceProvider, config) {
2608
2839
  this.app = app;
2609
2840
  this.heartbeatServiceProvider = heartbeatServiceProvider;
2841
+ this.appCheckServiceProvider = appCheckServiceProvider;
2610
2842
  this.config = config;
2611
2843
  this.currentUser = null;
2612
2844
  this.emulatorConfig = null;
@@ -2624,6 +2856,8 @@ var AuthImpl = /** @class */ (function () {
2624
2856
  this._initializationPromise = null;
2625
2857
  this._popupRedirectResolver = null;
2626
2858
  this._errorFactory = _DEFAULT_AUTH_ERROR_FACTORY;
2859
+ this._agentRecaptchaConfig = null;
2860
+ this._tenantRecaptchaConfigs = {};
2627
2861
  // Tracks the last notified UID for state change listeners to prevent
2628
2862
  // repeated calls to the callbacks. Undefined means it's never been
2629
2863
  // called, whereas null means it's been called with a signed out user
@@ -2953,6 +3187,41 @@ var AuthImpl = /** @class */ (function () {
2953
3187
  });
2954
3188
  }); });
2955
3189
  };
3190
+ AuthImpl.prototype.initializeRecaptchaConfig = function () {
3191
+ return tslib.__awaiter(this, void 0, void 0, function () {
3192
+ var response, config, verifier;
3193
+ return tslib.__generator(this, function (_a) {
3194
+ switch (_a.label) {
3195
+ case 0: return [4 /*yield*/, getRecaptchaConfig(this, {
3196
+ clientType: "CLIENT_TYPE_WEB" /* RecaptchaClientType.WEB */,
3197
+ version: "RECAPTCHA_ENTERPRISE" /* RecaptchaVersion.ENTERPRISE */
3198
+ })];
3199
+ case 1:
3200
+ response = _a.sent();
3201
+ config = new RecaptchaConfig(response);
3202
+ if (this.tenantId == null) {
3203
+ this._agentRecaptchaConfig = config;
3204
+ }
3205
+ else {
3206
+ this._tenantRecaptchaConfigs[this.tenantId] = config;
3207
+ }
3208
+ if (config.emailPasswordEnabled) {
3209
+ verifier = new RecaptchaEnterpriseVerifier(this);
3210
+ void verifier.verify();
3211
+ }
3212
+ return [2 /*return*/];
3213
+ }
3214
+ });
3215
+ });
3216
+ };
3217
+ AuthImpl.prototype._getRecaptchaConfig = function () {
3218
+ if (this.tenantId == null) {
3219
+ return this._agentRecaptchaConfig;
3220
+ }
3221
+ else {
3222
+ return this._tenantRecaptchaConfigs[this.tenantId];
3223
+ }
3224
+ };
2956
3225
  AuthImpl.prototype._getPersistence = function () {
2957
3226
  return this.assertedPersistence.persistence.type;
2958
3227
  };
@@ -3180,7 +3449,7 @@ var AuthImpl = /** @class */ (function () {
3180
3449
  AuthImpl.prototype._getAdditionalHeaders = function () {
3181
3450
  var _a;
3182
3451
  return tslib.__awaiter(this, void 0, void 0, function () {
3183
- var headers, heartbeatsHeader;
3452
+ var headers, heartbeatsHeader, appCheckToken;
3184
3453
  var _b;
3185
3454
  return tslib.__generator(this, function (_c) {
3186
3455
  switch (_c.label) {
@@ -3200,11 +3469,39 @@ var AuthImpl = /** @class */ (function () {
3200
3469
  if (heartbeatsHeader) {
3201
3470
  headers["X-Firebase-Client" /* HttpHeader.X_FIREBASE_CLIENT */] = heartbeatsHeader;
3202
3471
  }
3472
+ return [4 /*yield*/, this._getAppCheckToken()];
3473
+ case 2:
3474
+ appCheckToken = _c.sent();
3475
+ if (appCheckToken) {
3476
+ headers["X-Firebase-AppCheck" /* HttpHeader.X_FIREBASE_APP_CHECK */] = appCheckToken;
3477
+ }
3203
3478
  return [2 /*return*/, headers];
3204
3479
  }
3205
3480
  });
3206
3481
  });
3207
3482
  };
3483
+ AuthImpl.prototype._getAppCheckToken = function () {
3484
+ var _a;
3485
+ return tslib.__awaiter(this, void 0, void 0, function () {
3486
+ var appCheckTokenResult;
3487
+ return tslib.__generator(this, function (_b) {
3488
+ switch (_b.label) {
3489
+ case 0: return [4 /*yield*/, ((_a = this.appCheckServiceProvider
3490
+ .getImmediate({ optional: true })) === null || _a === void 0 ? void 0 : _a.getToken())];
3491
+ case 1:
3492
+ appCheckTokenResult = _b.sent();
3493
+ if (appCheckTokenResult === null || appCheckTokenResult === void 0 ? void 0 : appCheckTokenResult.error) {
3494
+ // Context: appCheck.getToken() will never throw even if an error happened.
3495
+ // In the error case, a dummy token will be returned along with an error field describing
3496
+ // the error. In general, we shouldn't care about the error condition and just use
3497
+ // the token (actual or dummy) to send requests.
3498
+ _logWarn("Error while retrieving App Check token: ".concat(appCheckTokenResult.error));
3499
+ }
3500
+ return [2 /*return*/, appCheckTokenResult === null || appCheckTokenResult === void 0 ? void 0 : appCheckTokenResult.token];
3501
+ }
3502
+ });
3503
+ });
3504
+ };
3208
3505
  return AuthImpl;
3209
3506
  }());
3210
3507
  /**
@@ -3235,6 +3532,74 @@ var Subscription = /** @class */ (function () {
3235
3532
  return Subscription;
3236
3533
  }());
3237
3534
 
3535
+ /**
3536
+ * @license
3537
+ * Copyright 2020 Google LLC
3538
+ *
3539
+ * Licensed under the Apache License, Version 2.0 (the "License");
3540
+ * you may not use this file except in compliance with the License.
3541
+ * You may obtain a copy of the License at
3542
+ *
3543
+ * http://www.apache.org/licenses/LICENSE-2.0
3544
+ *
3545
+ * Unless required by applicable law or agreed to in writing, software
3546
+ * distributed under the License is distributed on an "AS IS" BASIS,
3547
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3548
+ * See the License for the specific language governing permissions and
3549
+ * limitations under the License.
3550
+ */
3551
+ /**
3552
+ * Initializes an {@link Auth} instance with fine-grained control over
3553
+ * {@link Dependencies}.
3554
+ *
3555
+ * @remarks
3556
+ *
3557
+ * This function allows more control over the {@link Auth} instance than
3558
+ * {@link getAuth}. `getAuth` uses platform-specific defaults to supply
3559
+ * the {@link Dependencies}. In general, `getAuth` is the easiest way to
3560
+ * initialize Auth and works for most use cases. Use `initializeAuth` if you
3561
+ * need control over which persistence layer is used, or to minimize bundle
3562
+ * size if you're not using either `signInWithPopup` or `signInWithRedirect`.
3563
+ *
3564
+ * For example, if your app only uses anonymous accounts and you only want
3565
+ * accounts saved for the current session, initialize `Auth` with:
3566
+ *
3567
+ * ```js
3568
+ * const auth = initializeAuth(app, {
3569
+ * persistence: browserSessionPersistence,
3570
+ * popupRedirectResolver: undefined,
3571
+ * });
3572
+ * ```
3573
+ *
3574
+ * @public
3575
+ */
3576
+ function initializeAuth(app$1, deps) {
3577
+ var provider = app._getProvider(app$1, 'auth');
3578
+ if (provider.isInitialized()) {
3579
+ var auth_1 = provider.getImmediate();
3580
+ var initialOptions = provider.getOptions();
3581
+ if (util.deepEqual(initialOptions, deps !== null && deps !== void 0 ? deps : {})) {
3582
+ return auth_1;
3583
+ }
3584
+ else {
3585
+ _fail(auth_1, "already-initialized" /* AuthErrorCode.ALREADY_INITIALIZED */);
3586
+ }
3587
+ }
3588
+ var auth = provider.initialize({ options: deps });
3589
+ return auth;
3590
+ }
3591
+ function _initializeAuthInstance(auth, deps) {
3592
+ var persistence = (deps === null || deps === void 0 ? void 0 : deps.persistence) || [];
3593
+ var hierarchy = (Array.isArray(persistence) ? persistence : [persistence]).map(_getInstance);
3594
+ if (deps === null || deps === void 0 ? void 0 : deps.errorMap) {
3595
+ auth._updateErrorMap(deps.errorMap);
3596
+ }
3597
+ // This promise is intended to float; auth initialization happens in the
3598
+ // background, meanwhile the auth object may be used by the app.
3599
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
3600
+ auth._initializeWithPersistence(hierarchy, deps === null || deps === void 0 ? void 0 : deps.popupRedirectResolver);
3601
+ }
3602
+
3238
3603
  /**
3239
3604
  * Changes the {@link Auth} instance to communicate with the Firebase Auth Emulator, instead of production
3240
3605
  * Firebase Auth services.
@@ -3623,24 +3988,55 @@ var EmailAuthCredential = /** @class */ (function (_super) {
3623
3988
  };
3624
3989
  /** @internal */
3625
3990
  EmailAuthCredential.prototype._getIdTokenResponse = function (auth) {
3991
+ var _a;
3626
3992
  return tslib.__awaiter(this, void 0, void 0, function () {
3627
- return tslib.__generator(this, function (_a) {
3628
- switch (this.signInMethod) {
3629
- case "password" /* SignInMethod.EMAIL_PASSWORD */:
3630
- return [2 /*return*/, signInWithPassword(auth, {
3631
- returnSecureToken: true,
3632
- email: this._email,
3633
- password: this._password
3634
- })];
3635
- case "emailLink" /* SignInMethod.EMAIL_LINK */:
3636
- return [2 /*return*/, signInWithEmailLink$1(auth, {
3637
- email: this._email,
3638
- oobCode: this._password
3639
- })];
3640
- default:
3993
+ var _b, request_1, requestWithRecaptcha;
3994
+ var _this = this;
3995
+ return tslib.__generator(this, function (_c) {
3996
+ switch (_c.label) {
3997
+ case 0:
3998
+ _b = this.signInMethod;
3999
+ switch (_b) {
4000
+ case "password" /* SignInMethod.EMAIL_PASSWORD */: return [3 /*break*/, 1];
4001
+ case "emailLink" /* SignInMethod.EMAIL_LINK */: return [3 /*break*/, 4];
4002
+ }
4003
+ return [3 /*break*/, 5];
4004
+ case 1:
4005
+ request_1 = {
4006
+ returnSecureToken: true,
4007
+ email: this._email,
4008
+ password: this._password,
4009
+ clientType: "CLIENT_TYPE_WEB" /* RecaptchaClientType.WEB */
4010
+ };
4011
+ if (!((_a = auth._getRecaptchaConfig()) === null || _a === void 0 ? void 0 : _a.emailPasswordEnabled)) return [3 /*break*/, 3];
4012
+ return [4 /*yield*/, injectRecaptchaFields(auth, request_1, "signInWithPassword" /* RecaptchaActionName.SIGN_IN_WITH_PASSWORD */)];
4013
+ case 2:
4014
+ requestWithRecaptcha = _c.sent();
4015
+ return [2 /*return*/, signInWithPassword(auth, requestWithRecaptcha)];
4016
+ case 3: return [2 /*return*/, signInWithPassword(auth, request_1).catch(function (error) { return tslib.__awaiter(_this, void 0, void 0, function () {
4017
+ var requestWithRecaptcha;
4018
+ return tslib.__generator(this, function (_a) {
4019
+ switch (_a.label) {
4020
+ case 0:
4021
+ if (!(error.code === "auth/".concat("missing-recaptcha-token" /* AuthErrorCode.MISSING_RECAPTCHA_TOKEN */))) return [3 /*break*/, 2];
4022
+ 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.');
4023
+ return [4 /*yield*/, injectRecaptchaFields(auth, request_1, "signInWithPassword" /* RecaptchaActionName.SIGN_IN_WITH_PASSWORD */)];
4024
+ case 1:
4025
+ requestWithRecaptcha = _a.sent();
4026
+ return [2 /*return*/, signInWithPassword(auth, requestWithRecaptcha)];
4027
+ case 2: return [2 /*return*/, Promise.reject(error)];
4028
+ }
4029
+ });
4030
+ }); })];
4031
+ case 4: return [2 /*return*/, signInWithEmailLink$1(auth, {
4032
+ email: this._email,
4033
+ oobCode: this._password
4034
+ })];
4035
+ case 5:
3641
4036
  _fail(auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
4037
+ _c.label = 6;
4038
+ case 6: return [2 /*return*/];
3642
4039
  }
3643
- return [2 /*return*/];
3644
4040
  });
3645
4041
  });
3646
4042
  };
@@ -5820,23 +6216,61 @@ function _setActionCodeSettingsOnRequest(auth, request, actionCodeSettings) {
5820
6216
  * @public
5821
6217
  */
5822
6218
  function sendPasswordResetEmail(auth, email, actionCodeSettings) {
6219
+ var _a;
5823
6220
  return tslib.__awaiter(this, void 0, void 0, function () {
5824
- var authModular, request;
5825
- return tslib.__generator(this, function (_a) {
5826
- switch (_a.label) {
6221
+ var authInternal, request, requestWithRecaptcha;
6222
+ var _this = this;
6223
+ return tslib.__generator(this, function (_b) {
6224
+ switch (_b.label) {
5827
6225
  case 0:
5828
- authModular = util.getModularInstance(auth);
6226
+ authInternal = _castAuth(auth);
5829
6227
  request = {
5830
6228
  requestType: "PASSWORD_RESET" /* ActionCodeOperation.PASSWORD_RESET */,
5831
- email: email
6229
+ email: email,
6230
+ clientType: "CLIENT_TYPE_WEB" /* RecaptchaClientType.WEB */
5832
6231
  };
6232
+ if (!((_a = authInternal._getRecaptchaConfig()) === null || _a === void 0 ? void 0 : _a.emailPasswordEnabled)) return [3 /*break*/, 3];
6233
+ return [4 /*yield*/, injectRecaptchaFields(authInternal, request, "getOobCode" /* RecaptchaActionName.GET_OOB_CODE */, true)];
6234
+ case 1:
6235
+ requestWithRecaptcha = _b.sent();
5833
6236
  if (actionCodeSettings) {
5834
- _setActionCodeSettingsOnRequest(authModular, request, actionCodeSettings);
6237
+ _setActionCodeSettingsOnRequest(authInternal, requestWithRecaptcha, actionCodeSettings);
5835
6238
  }
5836
- return [4 /*yield*/, sendPasswordResetEmail$1(authModular, request)];
5837
- case 1:
5838
- _a.sent();
5839
- return [2 /*return*/];
6239
+ return [4 /*yield*/, sendPasswordResetEmail$1(authInternal, requestWithRecaptcha)];
6240
+ case 2:
6241
+ _b.sent();
6242
+ return [3 /*break*/, 5];
6243
+ case 3:
6244
+ if (actionCodeSettings) {
6245
+ _setActionCodeSettingsOnRequest(authInternal, request, actionCodeSettings);
6246
+ }
6247
+ return [4 /*yield*/, sendPasswordResetEmail$1(authInternal, request)
6248
+ .catch(function (error) { return tslib.__awaiter(_this, void 0, void 0, function () {
6249
+ var requestWithRecaptcha;
6250
+ return tslib.__generator(this, function (_a) {
6251
+ switch (_a.label) {
6252
+ case 0:
6253
+ if (!(error.code === "auth/".concat("missing-recaptcha-token" /* AuthErrorCode.MISSING_RECAPTCHA_TOKEN */))) return [3 /*break*/, 3];
6254
+ console.log('Password resets are protected by reCAPTCHA for this project. Automatically triggering the reCAPTCHA flow and restarting the password reset flow.');
6255
+ return [4 /*yield*/, injectRecaptchaFields(authInternal, request, "getOobCode" /* RecaptchaActionName.GET_OOB_CODE */, true)];
6256
+ case 1:
6257
+ requestWithRecaptcha = _a.sent();
6258
+ if (actionCodeSettings) {
6259
+ _setActionCodeSettingsOnRequest(authInternal, requestWithRecaptcha, actionCodeSettings);
6260
+ }
6261
+ return [4 /*yield*/, sendPasswordResetEmail$1(authInternal, requestWithRecaptcha)];
6262
+ case 2:
6263
+ _a.sent();
6264
+ return [3 /*break*/, 4];
6265
+ case 3: return [2 /*return*/, Promise.reject(error)];
6266
+ case 4: return [2 /*return*/];
6267
+ }
6268
+ });
6269
+ }); })];
6270
+ case 4:
6271
+ _b.sent();
6272
+ _b.label = 5;
6273
+ case 5: return [2 /*return*/];
5840
6274
  }
5841
6275
  });
5842
6276
  });
@@ -5981,25 +6415,54 @@ function verifyPasswordResetCode(auth, code) {
5981
6415
  * @public
5982
6416
  */
5983
6417
  function createUserWithEmailAndPassword(auth, email, password) {
6418
+ var _a;
5984
6419
  return tslib.__awaiter(this, void 0, void 0, function () {
5985
- var authInternal, response, userCredential;
5986
- return tslib.__generator(this, function (_a) {
5987
- switch (_a.label) {
6420
+ var authInternal, request, signUpResponse, requestWithRecaptcha, response, userCredential;
6421
+ var _this = this;
6422
+ return tslib.__generator(this, function (_b) {
6423
+ switch (_b.label) {
5988
6424
  case 0:
5989
6425
  authInternal = _castAuth(auth);
5990
- return [4 /*yield*/, signUp(authInternal, {
5991
- returnSecureToken: true,
5992
- email: email,
5993
- password: password
5994
- })];
6426
+ request = {
6427
+ returnSecureToken: true,
6428
+ email: email,
6429
+ password: password,
6430
+ clientType: "CLIENT_TYPE_WEB" /* RecaptchaClientType.WEB */
6431
+ };
6432
+ if (!((_a = authInternal._getRecaptchaConfig()) === null || _a === void 0 ? void 0 : _a.emailPasswordEnabled)) return [3 /*break*/, 2];
6433
+ return [4 /*yield*/, injectRecaptchaFields(authInternal, request, "signUpPassword" /* RecaptchaActionName.SIGN_UP_PASSWORD */)];
5995
6434
  case 1:
5996
- response = _a.sent();
5997
- return [4 /*yield*/, UserCredentialImpl._fromIdTokenResponse(authInternal, "signIn" /* OperationType.SIGN_IN */, response)];
6435
+ requestWithRecaptcha = _b.sent();
6436
+ signUpResponse = signUp(authInternal, requestWithRecaptcha);
6437
+ return [3 /*break*/, 3];
5998
6438
  case 2:
5999
- userCredential = _a.sent();
6439
+ signUpResponse = signUp(authInternal, request).catch(function (error) { return tslib.__awaiter(_this, void 0, void 0, function () {
6440
+ var requestWithRecaptcha;
6441
+ return tslib.__generator(this, function (_a) {
6442
+ switch (_a.label) {
6443
+ case 0:
6444
+ if (!(error.code === "auth/".concat("missing-recaptcha-token" /* AuthErrorCode.MISSING_RECAPTCHA_TOKEN */))) return [3 /*break*/, 2];
6445
+ console.log('Sign-up is protected by reCAPTCHA for this project. Automatically triggering the reCAPTCHA flow and restarting the sign-up flow.');
6446
+ return [4 /*yield*/, injectRecaptchaFields(authInternal, request, "signUpPassword" /* RecaptchaActionName.SIGN_UP_PASSWORD */)];
6447
+ case 1:
6448
+ requestWithRecaptcha = _a.sent();
6449
+ return [2 /*return*/, signUp(authInternal, requestWithRecaptcha)];
6450
+ case 2: return [2 /*return*/, Promise.reject(error)];
6451
+ }
6452
+ });
6453
+ }); });
6454
+ _b.label = 3;
6455
+ case 3: return [4 /*yield*/, signUpResponse.catch(function (error) {
6456
+ return Promise.reject(error);
6457
+ })];
6458
+ case 4:
6459
+ response = _b.sent();
6460
+ return [4 /*yield*/, UserCredentialImpl._fromIdTokenResponse(authInternal, "signIn" /* OperationType.SIGN_IN */, response)];
6461
+ case 5:
6462
+ userCredential = _b.sent();
6000
6463
  return [4 /*yield*/, authInternal._updateCurrentUser(userCredential.user)];
6001
- case 3:
6002
- _a.sent();
6464
+ case 6:
6465
+ _b.sent();
6003
6466
  return [2 /*return*/, userCredential];
6004
6467
  }
6005
6468
  });
@@ -6080,24 +6543,61 @@ function signInWithEmailAndPassword(auth, email, password) {
6080
6543
  * @public
6081
6544
  */
6082
6545
  function sendSignInLinkToEmail(auth, email, actionCodeSettings) {
6546
+ var _a;
6083
6547
  return tslib.__awaiter(this, void 0, void 0, function () {
6084
- var authModular, request;
6085
- return tslib.__generator(this, function (_a) {
6086
- switch (_a.label) {
6548
+ function setActionCodeSettings(request, actionCodeSettings) {
6549
+ _assert(actionCodeSettings.handleCodeInApp, authInternal, "argument-error" /* AuthErrorCode.ARGUMENT_ERROR */);
6550
+ if (actionCodeSettings) {
6551
+ _setActionCodeSettingsOnRequest(authInternal, request, actionCodeSettings);
6552
+ }
6553
+ }
6554
+ var authInternal, request, requestWithRecaptcha;
6555
+ var _this = this;
6556
+ return tslib.__generator(this, function (_b) {
6557
+ switch (_b.label) {
6087
6558
  case 0:
6088
- authModular = util.getModularInstance(auth);
6559
+ authInternal = _castAuth(auth);
6089
6560
  request = {
6090
6561
  requestType: "EMAIL_SIGNIN" /* ActionCodeOperation.EMAIL_SIGNIN */,
6091
- email: email
6562
+ email: email,
6563
+ clientType: "CLIENT_TYPE_WEB" /* RecaptchaClientType.WEB */
6092
6564
  };
6093
- _assert(actionCodeSettings.handleCodeInApp, authModular, "argument-error" /* AuthErrorCode.ARGUMENT_ERROR */);
6094
- if (actionCodeSettings) {
6095
- _setActionCodeSettingsOnRequest(authModular, request, actionCodeSettings);
6096
- }
6097
- return [4 /*yield*/, sendSignInLinkToEmail$1(authModular, request)];
6565
+ if (!((_a = authInternal._getRecaptchaConfig()) === null || _a === void 0 ? void 0 : _a.emailPasswordEnabled)) return [3 /*break*/, 3];
6566
+ return [4 /*yield*/, injectRecaptchaFields(authInternal, request, "getOobCode" /* RecaptchaActionName.GET_OOB_CODE */, true)];
6098
6567
  case 1:
6099
- _a.sent();
6100
- return [2 /*return*/];
6568
+ requestWithRecaptcha = _b.sent();
6569
+ setActionCodeSettings(requestWithRecaptcha, actionCodeSettings);
6570
+ return [4 /*yield*/, sendSignInLinkToEmail$1(authInternal, requestWithRecaptcha)];
6571
+ case 2:
6572
+ _b.sent();
6573
+ return [3 /*break*/, 5];
6574
+ case 3:
6575
+ setActionCodeSettings(request, actionCodeSettings);
6576
+ return [4 /*yield*/, sendSignInLinkToEmail$1(authInternal, request)
6577
+ .catch(function (error) { return tslib.__awaiter(_this, void 0, void 0, function () {
6578
+ var requestWithRecaptcha;
6579
+ return tslib.__generator(this, function (_a) {
6580
+ switch (_a.label) {
6581
+ case 0:
6582
+ if (!(error.code === "auth/".concat("missing-recaptcha-token" /* AuthErrorCode.MISSING_RECAPTCHA_TOKEN */))) return [3 /*break*/, 3];
6583
+ console.log('Email link sign-in is protected by reCAPTCHA for this project. Automatically triggering the reCAPTCHA flow and restarting the sign-in flow.');
6584
+ return [4 /*yield*/, injectRecaptchaFields(authInternal, request, "getOobCode" /* RecaptchaActionName.GET_OOB_CODE */, true)];
6585
+ case 1:
6586
+ requestWithRecaptcha = _a.sent();
6587
+ setActionCodeSettings(requestWithRecaptcha, actionCodeSettings);
6588
+ return [4 /*yield*/, sendSignInLinkToEmail$1(authInternal, requestWithRecaptcha)];
6589
+ case 2:
6590
+ _a.sent();
6591
+ return [3 /*break*/, 4];
6592
+ case 3: return [2 /*return*/, Promise.reject(error)];
6593
+ case 4: return [2 /*return*/];
6594
+ }
6595
+ });
6596
+ }); })];
6597
+ case 4:
6598
+ _b.sent();
6599
+ _b.label = 5;
6600
+ case 5: return [2 /*return*/];
6101
6601
  }
6102
6602
  });
6103
6603
  });
@@ -6693,6 +7193,35 @@ function getAdditionalUserInfo(userCredential) {
6693
7193
  function setPersistence(auth, persistence) {
6694
7194
  return util.getModularInstance(auth).setPersistence(persistence);
6695
7195
  }
7196
+ /**
7197
+ * Loads the reCAPTCHA configuration into the `Auth` instance.
7198
+ *
7199
+ * @remarks
7200
+ * This will load the reCAPTCHA config, which indicates whether the reCAPTCHA
7201
+ * verification flow should be triggered for each auth provider, into the
7202
+ * current Auth session.
7203
+ *
7204
+ * If initializeRecaptchaConfig() is not invoked, the auth flow will always start
7205
+ * without reCAPTCHA verification. If the provider is configured to require reCAPTCHA
7206
+ * verification, the SDK will transparently load the reCAPTCHA config and restart the
7207
+ * auth flows.
7208
+ *
7209
+ * Thus, by calling this optional method, you will reduce the latency of future auth flows.
7210
+ * Loading the reCAPTCHA config early will also enhance the signal collected by reCAPTCHA.
7211
+ *
7212
+ * @example
7213
+ * ```javascript
7214
+ * initializeRecaptchaConfig(auth);
7215
+ * ```
7216
+ *
7217
+ * @param auth - The {@link Auth} instance.
7218
+ *
7219
+ * @public
7220
+ */
7221
+ function initializeRecaptchaConfig(auth) {
7222
+ var authInternal = _castAuth(auth);
7223
+ return authInternal.initializeRecaptchaConfig();
7224
+ }
6696
7225
  /**
6697
7226
  * Adds an observer for changes to the signed-in user's ID token.
6698
7227
  *
@@ -7091,7 +7620,7 @@ function multiFactor(user) {
7091
7620
  }
7092
7621
 
7093
7622
  var name = "@firebase/auth";
7094
- var version = "0.22.0";
7623
+ var version = "0.23.0-canary.0a27d2fbf";
7095
7624
 
7096
7625
  /**
7097
7626
  * @license
@@ -7211,26 +7740,25 @@ function registerAuth(clientPlatform) {
7211
7740
  var deps = _a.options;
7212
7741
  var app = container.getProvider('app').getImmediate();
7213
7742
  var heartbeatServiceProvider = container.getProvider('heartbeat');
7743
+ var appCheckServiceProvider = container.getProvider('app-check-internal');
7214
7744
  var _b = app.options, apiKey = _b.apiKey, authDomain = _b.authDomain;
7215
- return (function (app, heartbeatServiceProvider) {
7216
- _assert(apiKey && !apiKey.includes(':'), "invalid-api-key" /* AuthErrorCode.INVALID_API_KEY */, { appName: app.name });
7217
- // Auth domain is optional if IdP sign in isn't being used
7218
- _assert(!(authDomain === null || authDomain === void 0 ? void 0 : authDomain.includes(':')), "argument-error" /* AuthErrorCode.ARGUMENT_ERROR */, {
7219
- appName: app.name
7220
- });
7221
- var config = {
7222
- apiKey: apiKey,
7223
- authDomain: authDomain,
7224
- clientPlatform: clientPlatform,
7225
- apiHost: "identitytoolkit.googleapis.com" /* DefaultConfig.API_HOST */,
7226
- tokenApiHost: "securetoken.googleapis.com" /* DefaultConfig.TOKEN_API_HOST */,
7227
- apiScheme: "https" /* DefaultConfig.API_SCHEME */,
7228
- sdkClientVersion: _getClientVersion(clientPlatform)
7229
- };
7230
- var authInstance = new AuthImpl(app, heartbeatServiceProvider, config);
7231
- _initializeAuthInstance(authInstance, deps);
7232
- return authInstance;
7233
- })(app, heartbeatServiceProvider);
7745
+ _assert(apiKey && !apiKey.includes(':'), "invalid-api-key" /* AuthErrorCode.INVALID_API_KEY */, { appName: app.name });
7746
+ // Auth domain is optional if IdP sign in isn't being used
7747
+ _assert(!(authDomain === null || authDomain === void 0 ? void 0 : authDomain.includes(':')), "argument-error" /* AuthErrorCode.ARGUMENT_ERROR */, {
7748
+ appName: app.name
7749
+ });
7750
+ var config = {
7751
+ apiKey: apiKey,
7752
+ authDomain: authDomain,
7753
+ clientPlatform: clientPlatform,
7754
+ apiHost: "identitytoolkit.googleapis.com" /* DefaultConfig.API_HOST */,
7755
+ tokenApiHost: "securetoken.googleapis.com" /* DefaultConfig.TOKEN_API_HOST */,
7756
+ apiScheme: "https" /* DefaultConfig.API_SCHEME */,
7757
+ sdkClientVersion: _getClientVersion(clientPlatform)
7758
+ };
7759
+ var authInstance = new AuthImpl(app, heartbeatServiceProvider, appCheckServiceProvider, config);
7760
+ _initializeAuthInstance(authInstance, deps);
7761
+ return authInstance;
7234
7762
  }, "PUBLIC" /* ComponentType.PUBLIC */)
7235
7763
  /**
7236
7764
  * Auth can only be initialized by explicitly calling getAuth() or initializeAuth()
@@ -7626,6 +8154,7 @@ exports.getRedirectResult = getRedirectResult;
7626
8154
  exports.inMemoryPersistence = inMemoryPersistence;
7627
8155
  exports.indexedDBLocalPersistence = indexedDBLocalPersistence;
7628
8156
  exports.initializeAuth = initializeAuth;
8157
+ exports.initializeRecaptchaConfig = initializeRecaptchaConfig;
7629
8158
  exports.isSignInWithEmailLink = isSignInWithEmailLink;
7630
8159
  exports.linkWithCredential = linkWithCredential;
7631
8160
  exports.linkWithPhoneNumber = linkWithPhoneNumber;
@@ -7664,4 +8193,4 @@ exports.updateProfile = updateProfile;
7664
8193
  exports.useDeviceLanguage = useDeviceLanguage;
7665
8194
  exports.verifyBeforeUpdateEmail = verifyBeforeUpdateEmail;
7666
8195
  exports.verifyPasswordResetCode = verifyPasswordResetCode;
7667
- //# sourceMappingURL=totp-416a2adc.js.map
8196
+ //# sourceMappingURL=totp-c1b55906.js.map