@firebase/auth 0.19.12 → 0.20.0

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 (121) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/auth-public.d.ts +30 -0
  3. package/dist/auth.d.ts +38 -1
  4. package/dist/cordova/index.js +2 -2
  5. package/dist/cordova/internal/index.d.ts +1 -0
  6. package/dist/cordova/internal.js +3 -2
  7. package/dist/cordova/internal.js.map +1 -1
  8. package/dist/cordova/{popup_redirect-fd81f644.js → popup_redirect-1228b67a.js} +203 -43
  9. package/dist/cordova/popup_redirect-1228b67a.js.map +1 -0
  10. package/dist/cordova/src/core/auth/auth_impl.d.ts +3 -1
  11. package/dist/cordova/src/core/auth/middleware.d.ts +25 -0
  12. package/dist/cordova/src/core/auth/middleware.test.d.ts +17 -0
  13. package/dist/cordova/src/core/errors.d.ts +7 -1
  14. package/dist/cordova/src/core/index.d.ts +11 -0
  15. package/dist/cordova/src/core/strategies/redirect.d.ts +1 -0
  16. package/dist/cordova/src/model/popup_redirect.d.ts +2 -0
  17. package/dist/cordova/src/model/public_types.d.ts +10 -0
  18. package/dist/cordova/test/integration/flows/middleware_test_generator.d.ts +18 -0
  19. package/dist/cordova/test/integration/webdriver/util/functions.d.ts +4 -0
  20. package/dist/esm2017/{index-7078a255.js → index-815f1b87.js} +143 -18
  21. package/dist/esm2017/index-815f1b87.js.map +1 -0
  22. package/dist/esm2017/index.js +1 -1
  23. package/dist/esm2017/internal/index.d.ts +1 -0
  24. package/dist/esm2017/internal.js +3 -2
  25. package/dist/esm2017/internal.js.map +1 -1
  26. package/dist/esm2017/src/core/auth/auth_impl.d.ts +3 -1
  27. package/dist/esm2017/src/core/auth/middleware.d.ts +25 -0
  28. package/dist/esm2017/src/core/auth/middleware.test.d.ts +17 -0
  29. package/dist/esm2017/src/core/errors.d.ts +7 -1
  30. package/dist/esm2017/src/core/index.d.ts +11 -0
  31. package/dist/esm2017/src/core/strategies/redirect.d.ts +1 -0
  32. package/dist/esm2017/src/model/popup_redirect.d.ts +2 -0
  33. package/dist/esm2017/src/model/public_types.d.ts +10 -0
  34. package/dist/esm2017/test/integration/flows/middleware_test_generator.d.ts +18 -0
  35. package/dist/esm2017/test/integration/webdriver/util/functions.d.ts +4 -0
  36. package/dist/esm5/{index-7a476dcd.js → index-dc27d95e.js} +203 -43
  37. package/dist/esm5/index-dc27d95e.js.map +1 -0
  38. package/dist/esm5/index.js +1 -1
  39. package/dist/esm5/internal/index.d.ts +1 -0
  40. package/dist/esm5/internal.js +3 -2
  41. package/dist/esm5/internal.js.map +1 -1
  42. package/dist/esm5/src/core/auth/auth_impl.d.ts +3 -1
  43. package/dist/esm5/src/core/auth/middleware.d.ts +25 -0
  44. package/dist/esm5/src/core/auth/middleware.test.d.ts +17 -0
  45. package/dist/esm5/src/core/errors.d.ts +7 -1
  46. package/dist/esm5/src/core/index.d.ts +11 -0
  47. package/dist/esm5/src/core/strategies/redirect.d.ts +1 -0
  48. package/dist/esm5/src/model/popup_redirect.d.ts +2 -0
  49. package/dist/esm5/src/model/public_types.d.ts +10 -0
  50. package/dist/esm5/test/integration/flows/middleware_test_generator.d.ts +18 -0
  51. package/dist/esm5/test/integration/webdriver/util/functions.d.ts +4 -0
  52. package/dist/index.webworker.esm5.js +198 -42
  53. package/dist/index.webworker.esm5.js.map +1 -1
  54. package/dist/internal/index.d.ts +1 -0
  55. package/dist/node/{index-eabd3e6c.js → index-ec34877a.js} +199 -42
  56. package/dist/node/index-ec34877a.js.map +1 -0
  57. package/dist/node/index.js +2 -1
  58. package/dist/node/index.js.map +1 -1
  59. package/dist/node/internal/index.d.ts +1 -0
  60. package/dist/node/internal.js +7 -1
  61. package/dist/node/internal.js.map +1 -1
  62. package/dist/node/src/core/auth/auth_impl.d.ts +3 -1
  63. package/dist/node/src/core/auth/middleware.d.ts +25 -0
  64. package/dist/node/src/core/auth/middleware.test.d.ts +17 -0
  65. package/dist/node/src/core/errors.d.ts +7 -1
  66. package/dist/node/src/core/index.d.ts +11 -0
  67. package/dist/node/src/core/strategies/redirect.d.ts +1 -0
  68. package/dist/node/src/model/popup_redirect.d.ts +2 -0
  69. package/dist/node/src/model/public_types.d.ts +10 -0
  70. package/dist/node/test/integration/flows/middleware_test_generator.d.ts +18 -0
  71. package/dist/node/test/integration/webdriver/util/functions.d.ts +4 -0
  72. package/dist/node-esm/{index-d709908a.js → index-c85cf380.js} +139 -18
  73. package/dist/node-esm/index-c85cf380.js.map +1 -0
  74. package/dist/node-esm/index.js +1 -1
  75. package/dist/node-esm/internal/index.d.ts +1 -0
  76. package/dist/node-esm/internal.js +7 -3
  77. package/dist/node-esm/internal.js.map +1 -1
  78. package/dist/node-esm/src/core/auth/auth_impl.d.ts +3 -1
  79. package/dist/node-esm/src/core/auth/middleware.d.ts +25 -0
  80. package/dist/node-esm/src/core/auth/middleware.test.d.ts +17 -0
  81. package/dist/node-esm/src/core/errors.d.ts +7 -1
  82. package/dist/node-esm/src/core/index.d.ts +11 -0
  83. package/dist/node-esm/src/core/strategies/redirect.d.ts +1 -0
  84. package/dist/node-esm/src/model/popup_redirect.d.ts +2 -0
  85. package/dist/node-esm/src/model/public_types.d.ts +10 -0
  86. package/dist/node-esm/test/integration/flows/middleware_test_generator.d.ts +18 -0
  87. package/dist/node-esm/test/integration/webdriver/util/functions.d.ts +4 -0
  88. package/dist/rn/index.js +2 -1
  89. package/dist/rn/index.js.map +1 -1
  90. package/dist/rn/internal/index.d.ts +1 -0
  91. package/dist/rn/internal.js +8 -1
  92. package/dist/rn/internal.js.map +1 -1
  93. package/dist/rn/{phone-eec7f987.js → phone-ae029e3c.js} +199 -42
  94. package/dist/rn/phone-ae029e3c.js.map +1 -0
  95. package/dist/rn/src/core/auth/auth_impl.d.ts +3 -1
  96. package/dist/rn/src/core/auth/middleware.d.ts +25 -0
  97. package/dist/rn/src/core/auth/middleware.test.d.ts +17 -0
  98. package/dist/rn/src/core/errors.d.ts +7 -1
  99. package/dist/rn/src/core/index.d.ts +11 -0
  100. package/dist/rn/src/core/strategies/redirect.d.ts +1 -0
  101. package/dist/rn/src/model/popup_redirect.d.ts +2 -0
  102. package/dist/rn/src/model/public_types.d.ts +10 -0
  103. package/dist/rn/test/integration/flows/middleware_test_generator.d.ts +18 -0
  104. package/dist/rn/test/integration/webdriver/util/functions.d.ts +4 -0
  105. package/dist/src/core/auth/auth_impl.d.ts +3 -1
  106. package/dist/src/core/auth/middleware.d.ts +25 -0
  107. package/dist/src/core/auth/middleware.test.d.ts +17 -0
  108. package/dist/src/core/errors.d.ts +7 -1
  109. package/dist/src/core/index.d.ts +11 -0
  110. package/dist/src/core/strategies/redirect.d.ts +1 -0
  111. package/dist/src/model/popup_redirect.d.ts +2 -0
  112. package/dist/src/model/public_types.d.ts +10 -0
  113. package/dist/test/integration/flows/middleware_test_generator.d.ts +18 -0
  114. package/dist/test/integration/webdriver/util/functions.d.ts +4 -0
  115. package/package.json +6 -6
  116. package/dist/cordova/popup_redirect-fd81f644.js.map +0 -1
  117. package/dist/esm2017/index-7078a255.js.map +0 -1
  118. package/dist/esm5/index-7a476dcd.js.map +0 -1
  119. package/dist/node/index-eabd3e6c.js.map +0 -1
  120. package/dist/node-esm/index-d709908a.js.map +0 -1
  121. package/dist/rn/phone-eec7f987.js.map +0 -1
@@ -1015,6 +1015,7 @@ function _debugErrorMap() {
1015
1015
  'Please fix by going to the Auth email templates section in the Firebase Console.',
1016
1016
  _a["invalid-verification-id" /* INVALID_SESSION_INFO */] = 'The verification ID used to create the phone auth credential is invalid.',
1017
1017
  _a["invalid-tenant-id" /* INVALID_TENANT_ID */] = "The Auth instance's tenant ID is invalid.",
1018
+ _a["login-blocked" /* LOGIN_BLOCKED */] = "Login blocked by user-provided method: {$originalMessage}",
1018
1019
  _a["missing-android-pkg-name" /* MISSING_ANDROID_PACKAGE_NAME */] = 'An Android Package Name must be provided if the Android App is required to be installed.',
1019
1020
  _a["auth-domain-config-required" /* MISSING_AUTH_DOMAIN */] = 'Be sure to include authDomain when calling firebase.initializeApp(), ' +
1020
1021
  'by following the instructions in the Firebase console.',
@@ -3279,6 +3280,104 @@ function _getClientVersion(clientPlatform, frameworks) {
3279
3280
  return reportedPlatform + "/" + "JsCore" /* CORE */ + "/" + SDK_VERSION + "/" + reportedFrameworks;
3280
3281
  }
3281
3282
 
3283
+ /**
3284
+ * @license
3285
+ * Copyright 2022 Google LLC
3286
+ *
3287
+ * Licensed under the Apache License, Version 2.0 (the "License");
3288
+ * you may not use this file except in compliance with the License.
3289
+ * You may obtain a copy of the License at
3290
+ *
3291
+ * http://www.apache.org/licenses/LICENSE-2.0
3292
+ *
3293
+ * Unless required by applicable law or agreed to in writing, software
3294
+ * distributed under the License is distributed on an "AS IS" BASIS,
3295
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3296
+ * See the License for the specific language governing permissions and
3297
+ * limitations under the License.
3298
+ */
3299
+ var AuthMiddlewareQueue = /** @class */ (function () {
3300
+ function AuthMiddlewareQueue(auth) {
3301
+ this.auth = auth;
3302
+ this.queue = [];
3303
+ }
3304
+ AuthMiddlewareQueue.prototype.pushCallback = function (callback, onAbort) {
3305
+ var _this = this;
3306
+ // The callback could be sync or async. Wrap it into a
3307
+ // function that is always async.
3308
+ var wrappedCallback = function (user) { return new Promise(function (resolve, reject) {
3309
+ try {
3310
+ var result = callback(user);
3311
+ // Either resolve with existing promise or wrap a non-promise
3312
+ // return value into a promise.
3313
+ resolve(result);
3314
+ }
3315
+ catch (e) {
3316
+ // Sync callback throws.
3317
+ reject(e);
3318
+ }
3319
+ }); };
3320
+ // Attach the onAbort if present
3321
+ wrappedCallback.onAbort = onAbort;
3322
+ this.queue.push(wrappedCallback);
3323
+ var index = this.queue.length - 1;
3324
+ return function () {
3325
+ // Unsubscribe. Replace with no-op. Do not remove from array, or it will disturb
3326
+ // indexing of other elements.
3327
+ _this.queue[index] = function () { return Promise.resolve(); };
3328
+ };
3329
+ };
3330
+ AuthMiddlewareQueue.prototype.runMiddleware = function (nextUser) {
3331
+ return __awaiter(this, void 0, void 0, function () {
3332
+ var onAbortStack, _i, _a, beforeStateCallback, e_1, _b, onAbortStack_1, onAbort;
3333
+ return __generator(this, function (_c) {
3334
+ switch (_c.label) {
3335
+ case 0:
3336
+ if (this.auth.currentUser === nextUser) {
3337
+ return [2 /*return*/];
3338
+ }
3339
+ onAbortStack = [];
3340
+ _c.label = 1;
3341
+ case 1:
3342
+ _c.trys.push([1, 6, , 7]);
3343
+ _i = 0, _a = this.queue;
3344
+ _c.label = 2;
3345
+ case 2:
3346
+ if (!(_i < _a.length)) return [3 /*break*/, 5];
3347
+ beforeStateCallback = _a[_i];
3348
+ return [4 /*yield*/, beforeStateCallback(nextUser)];
3349
+ case 3:
3350
+ _c.sent();
3351
+ // Only push the onAbort if the callback succeeds
3352
+ if (beforeStateCallback.onAbort) {
3353
+ onAbortStack.push(beforeStateCallback.onAbort);
3354
+ }
3355
+ _c.label = 4;
3356
+ case 4:
3357
+ _i++;
3358
+ return [3 /*break*/, 2];
3359
+ case 5: return [3 /*break*/, 7];
3360
+ case 6:
3361
+ e_1 = _c.sent();
3362
+ // Run all onAbort, with separate try/catch to ignore any errors and
3363
+ // continue
3364
+ onAbortStack.reverse();
3365
+ for (_b = 0, onAbortStack_1 = onAbortStack; _b < onAbortStack_1.length; _b++) {
3366
+ onAbort = onAbortStack_1[_b];
3367
+ try {
3368
+ onAbort();
3369
+ }
3370
+ catch (_) { /* swallow error */ }
3371
+ }
3372
+ throw this.auth._errorFactory.create("login-blocked" /* LOGIN_BLOCKED */, { originalMessage: e_1.message });
3373
+ case 7: return [2 /*return*/];
3374
+ }
3375
+ });
3376
+ });
3377
+ };
3378
+ return AuthMiddlewareQueue;
3379
+ }());
3380
+
3282
3381
  /**
3283
3382
  * @license
3284
3383
  * Copyright 2020 Google LLC
@@ -3305,6 +3404,7 @@ var AuthImpl = /** @class */ (function () {
3305
3404
  this.operations = Promise.resolve();
3306
3405
  this.authStateSubscription = new Subscription(this);
3307
3406
  this.idTokenSubscription = new Subscription(this);
3407
+ this.beforeStateQueue = new AuthMiddlewareQueue(this);
3308
3408
  this.redirectUser = null;
3309
3409
  this.isProactiveRefreshEnabled = false;
3310
3410
  // Any network calls will set this to true and prevent subsequent emulator
@@ -3406,9 +3506,11 @@ var AuthImpl = /** @class */ (function () {
3406
3506
  return [2 /*return*/];
3407
3507
  case 3:
3408
3508
  // Update current Auth state. Either a new login or logout.
3409
- return [4 /*yield*/, this._updateCurrentUser(user)];
3509
+ // Skip blocking callbacks, they should not apply to a change in another tab.
3510
+ return [4 /*yield*/, this._updateCurrentUser(user, /* skipBeforeStateCallbacks */ true)];
3410
3511
  case 4:
3411
3512
  // Update current Auth state. Either a new login or logout.
3513
+ // Skip blocking callbacks, they should not apply to a change in another tab.
3412
3514
  _a.sent();
3413
3515
  return [2 /*return*/];
3414
3516
  }
@@ -3418,18 +3520,20 @@ var AuthImpl = /** @class */ (function () {
3418
3520
  AuthImpl.prototype.initializeCurrentUser = function (popupRedirectResolver) {
3419
3521
  var _a;
3420
3522
  return __awaiter(this, void 0, void 0, function () {
3421
- var storedUser, redirectUserEventId, storedUserEventId, result;
3523
+ var previouslyStoredUser, futureCurrentUser, needsTocheckMiddleware, redirectUserEventId, storedUserEventId, result, e_2;
3422
3524
  return __generator(this, function (_b) {
3423
3525
  switch (_b.label) {
3424
3526
  case 0: return [4 /*yield*/, this.assertedPersistence.getCurrentUser()];
3425
3527
  case 1:
3426
- storedUser = (_b.sent());
3528
+ previouslyStoredUser = (_b.sent());
3529
+ futureCurrentUser = previouslyStoredUser;
3530
+ needsTocheckMiddleware = false;
3427
3531
  if (!(popupRedirectResolver && this.config.authDomain)) return [3 /*break*/, 4];
3428
3532
  return [4 /*yield*/, this.getOrInitRedirectPersistenceManager()];
3429
3533
  case 2:
3430
3534
  _b.sent();
3431
3535
  redirectUserEventId = (_a = this.redirectUser) === null || _a === void 0 ? void 0 : _a._redirectEventId;
3432
- storedUserEventId = storedUser === null || storedUser === void 0 ? void 0 : storedUser._redirectEventId;
3536
+ storedUserEventId = futureCurrentUser === null || futureCurrentUser === void 0 ? void 0 : futureCurrentUser._redirectEventId;
3433
3537
  return [4 /*yield*/, this.tryRedirectSignIn(popupRedirectResolver)];
3434
3538
  case 3:
3435
3539
  result = _b.sent();
@@ -3439,32 +3543,51 @@ var AuthImpl = /** @class */ (function () {
3439
3543
  // TODO(samgho): More thoroughly test all of this
3440
3544
  if ((!redirectUserEventId || redirectUserEventId === storedUserEventId) &&
3441
3545
  (result === null || result === void 0 ? void 0 : result.user)) {
3442
- storedUser = result.user;
3546
+ futureCurrentUser = result.user;
3547
+ needsTocheckMiddleware = true;
3443
3548
  }
3444
3549
  _b.label = 4;
3445
3550
  case 4:
3446
3551
  // If no user in persistence, there is no current user. Set to null.
3447
- if (!storedUser) {
3552
+ if (!futureCurrentUser) {
3448
3553
  return [2 /*return*/, this.directlySetCurrentUser(null)];
3449
3554
  }
3450
- if (!storedUser._redirectEventId) {
3451
- // This isn't a redirect user, we can reload and bail
3452
- // This will also catch the redirected user, if available, as that method
3453
- // strips the _redirectEventId
3454
- return [2 /*return*/, this.reloadAndSetCurrentUserOrClear(storedUser)];
3555
+ if (!!futureCurrentUser._redirectEventId) return [3 /*break*/, 9];
3556
+ if (!needsTocheckMiddleware) return [3 /*break*/, 8];
3557
+ _b.label = 5;
3558
+ case 5:
3559
+ _b.trys.push([5, 7, , 8]);
3560
+ return [4 /*yield*/, this.beforeStateQueue.runMiddleware(futureCurrentUser)];
3561
+ case 6:
3562
+ _b.sent();
3563
+ return [3 /*break*/, 8];
3564
+ case 7:
3565
+ e_2 = _b.sent();
3566
+ futureCurrentUser = previouslyStoredUser;
3567
+ // We know this is available since the bit is only set when the
3568
+ // resolver is available
3569
+ this._popupRedirectResolver._overrideRedirectResult(this, function () { return Promise.reject(e_2); });
3570
+ return [3 /*break*/, 8];
3571
+ case 8:
3572
+ if (futureCurrentUser) {
3573
+ return [2 /*return*/, this.reloadAndSetCurrentUserOrClear(futureCurrentUser)];
3455
3574
  }
3575
+ else {
3576
+ return [2 /*return*/, this.directlySetCurrentUser(null)];
3577
+ }
3578
+ case 9:
3456
3579
  _assert(this._popupRedirectResolver, this, "argument-error" /* ARGUMENT_ERROR */);
3457
3580
  return [4 /*yield*/, this.getOrInitRedirectPersistenceManager()];
3458
- case 5:
3581
+ case 10:
3459
3582
  _b.sent();
3460
3583
  // If the redirect user's event ID matches the current user's event ID,
3461
3584
  // DO NOT reload the current user, otherwise they'll be cleared from storage.
3462
3585
  // This is important for the reauthenticateWithRedirect() flow.
3463
3586
  if (this.redirectUser &&
3464
- this.redirectUser._redirectEventId === storedUser._redirectEventId) {
3465
- return [2 /*return*/, this.directlySetCurrentUser(storedUser)];
3587
+ this.redirectUser._redirectEventId === futureCurrentUser._redirectEventId) {
3588
+ return [2 /*return*/, this.directlySetCurrentUser(futureCurrentUser)];
3466
3589
  }
3467
- return [2 /*return*/, this.reloadAndSetCurrentUserOrClear(storedUser)];
3590
+ return [2 /*return*/, this.reloadAndSetCurrentUserOrClear(futureCurrentUser)];
3468
3591
  }
3469
3592
  });
3470
3593
  });
@@ -3502,7 +3625,7 @@ var AuthImpl = /** @class */ (function () {
3502
3625
  };
3503
3626
  AuthImpl.prototype.reloadAndSetCurrentUserOrClear = function (user) {
3504
3627
  return __awaiter(this, void 0, void 0, function () {
3505
- var e_3;
3628
+ var e_4;
3506
3629
  return __generator(this, function (_a) {
3507
3630
  switch (_a.label) {
3508
3631
  case 0:
@@ -3512,8 +3635,8 @@ var AuthImpl = /** @class */ (function () {
3512
3635
  _a.sent();
3513
3636
  return [3 /*break*/, 3];
3514
3637
  case 2:
3515
- e_3 = _a.sent();
3516
- if (e_3.code !== "auth/" + "network-request-failed" /* NETWORK_REQUEST_FAILED */) {
3638
+ e_4 = _a.sent();
3639
+ if (e_4.code !== "auth/" + "network-request-failed" /* NETWORK_REQUEST_FAILED */) {
3517
3640
  // Something's wrong with the user's token. Log them out and remove
3518
3641
  // them from storage
3519
3642
  return [2 /*return*/, this.directlySetCurrentUser(null)];
@@ -3549,27 +3672,36 @@ var AuthImpl = /** @class */ (function () {
3549
3672
  });
3550
3673
  });
3551
3674
  };
3552
- AuthImpl.prototype._updateCurrentUser = function (user) {
3675
+ AuthImpl.prototype._updateCurrentUser = function (user, skipBeforeStateCallbacks) {
3676
+ if (skipBeforeStateCallbacks === void 0) { skipBeforeStateCallbacks = false; }
3553
3677
  return __awaiter(this, void 0, void 0, function () {
3554
3678
  var _this = this;
3555
3679
  return __generator(this, function (_a) {
3556
- if (this._deleted) {
3557
- return [2 /*return*/];
3558
- }
3559
- if (user) {
3560
- _assert(this.tenantId === user.tenantId, this, "tenant-id-mismatch" /* TENANT_ID_MISMATCH */);
3680
+ switch (_a.label) {
3681
+ case 0:
3682
+ if (this._deleted) {
3683
+ return [2 /*return*/];
3684
+ }
3685
+ if (user) {
3686
+ _assert(this.tenantId === user.tenantId, this, "tenant-id-mismatch" /* TENANT_ID_MISMATCH */);
3687
+ }
3688
+ if (!!skipBeforeStateCallbacks) return [3 /*break*/, 2];
3689
+ return [4 /*yield*/, this.beforeStateQueue.runMiddleware(user)];
3690
+ case 1:
3691
+ _a.sent();
3692
+ _a.label = 2;
3693
+ case 2: return [2 /*return*/, this.queue(function () { return __awaiter(_this, void 0, void 0, function () {
3694
+ return __generator(this, function (_a) {
3695
+ switch (_a.label) {
3696
+ case 0: return [4 /*yield*/, this.directlySetCurrentUser(user)];
3697
+ case 1:
3698
+ _a.sent();
3699
+ this.notifyAuthListeners();
3700
+ return [2 /*return*/];
3701
+ }
3702
+ });
3703
+ }); })];
3561
3704
  }
3562
- return [2 /*return*/, this.queue(function () { return __awaiter(_this, void 0, void 0, function () {
3563
- return __generator(this, function (_a) {
3564
- switch (_a.label) {
3565
- case 0: return [4 /*yield*/, this.directlySetCurrentUser(user)];
3566
- case 1:
3567
- _a.sent();
3568
- this.notifyAuthListeners();
3569
- return [2 /*return*/];
3570
- }
3571
- });
3572
- }); })];
3573
3705
  });
3574
3706
  });
3575
3707
  };
@@ -3577,13 +3709,21 @@ var AuthImpl = /** @class */ (function () {
3577
3709
  return __awaiter(this, void 0, void 0, function () {
3578
3710
  return __generator(this, function (_a) {
3579
3711
  switch (_a.label) {
3580
- case 0:
3581
- if (!(this.redirectPersistenceManager || this._popupRedirectResolver)) return [3 /*break*/, 2];
3582
- return [4 /*yield*/, this._setRedirectUser(null)];
3712
+ case 0:
3713
+ // Run first, to block _setRedirectUser() if any callbacks fail.
3714
+ return [4 /*yield*/, this.beforeStateQueue.runMiddleware(null)];
3583
3715
  case 1:
3716
+ // Run first, to block _setRedirectUser() if any callbacks fail.
3584
3717
  _a.sent();
3585
- _a.label = 2;
3586
- case 2: return [2 /*return*/, this._updateCurrentUser(null)];
3718
+ if (!(this.redirectPersistenceManager || this._popupRedirectResolver)) return [3 /*break*/, 3];
3719
+ return [4 /*yield*/, this._setRedirectUser(null)];
3720
+ case 2:
3721
+ _a.sent();
3722
+ _a.label = 3;
3723
+ case 3:
3724
+ // Prevent callbacks from being called again in _updateCurrentUser, as
3725
+ // they were already called in the first line.
3726
+ return [2 /*return*/, this._updateCurrentUser(null, /* skipBeforeStateCallbacks */ true)];
3587
3727
  }
3588
3728
  });
3589
3729
  });
@@ -3610,6 +3750,9 @@ var AuthImpl = /** @class */ (function () {
3610
3750
  AuthImpl.prototype.onAuthStateChanged = function (nextOrObserver, error, completed) {
3611
3751
  return this.registerStateListener(this.authStateSubscription, nextOrObserver, error, completed);
3612
3752
  };
3753
+ AuthImpl.prototype.beforeAuthStateChanged = function (callback, onAbort) {
3754
+ return this.beforeStateQueue.pushCallback(callback, onAbort);
3755
+ };
3613
3756
  AuthImpl.prototype.onIdTokenChanged = function (nextOrObserver, error, completed) {
3614
3757
  return this.registerStateListener(this.idTokenSubscription, nextOrObserver, error, completed);
3615
3758
  };
@@ -7345,6 +7488,19 @@ function setPersistence(auth, persistence) {
7345
7488
  function onIdTokenChanged(auth, nextOrObserver, error, completed) {
7346
7489
  return getModularInstance(auth).onIdTokenChanged(nextOrObserver, error, completed);
7347
7490
  }
7491
+ /**
7492
+ * Adds a blocking callback that runs before an auth state change
7493
+ * sets a new user.
7494
+ *
7495
+ * @param auth - The {@link Auth} instance.
7496
+ * @param callback - callback triggered before new user value is set.
7497
+ * If this throws, it blocks the user from being set.
7498
+ * @param onAbort - callback triggered if a later `beforeAuthStateChanged()`
7499
+ * callback throws, allowing you to undo any side effects.
7500
+ */
7501
+ function beforeAuthStateChanged(auth, callback, onAbort) {
7502
+ return getModularInstance(auth).beforeAuthStateChanged(callback, onAbort);
7503
+ }
7348
7504
  /**
7349
7505
  * Adds an observer for changes to the user's sign-in state.
7350
7506
  *
@@ -7711,7 +7867,7 @@ function multiFactor(user) {
7711
7867
  }
7712
7868
 
7713
7869
  var name = "@firebase/auth";
7714
- var version = "0.19.12";
7870
+ var version = "0.20.0";
7715
7871
 
7716
7872
  /**
7717
7873
  * @license
@@ -8702,6 +8858,9 @@ function _setPendingRedirectStatus(resolver, auth) {
8702
8858
  function _clearRedirectOutcomes() {
8703
8859
  redirectOutcomeMap.clear();
8704
8860
  }
8861
+ function _overrideRedirectResult(auth, result) {
8862
+ redirectOutcomeMap.set(auth._key(), result);
8863
+ }
8705
8864
  function resolverPersistence(resolver) {
8706
8865
  return _getInstance(resolver._redirectPersistence);
8707
8866
  }
@@ -9694,6 +9853,7 @@ var CordovaPopupRedirectResolver = /** @class */ (function () {
9694
9853
  this.eventManagers = new Map();
9695
9854
  this.originValidationPromises = {};
9696
9855
  this._completeRedirectFn = _getRedirectResult;
9856
+ this._overrideRedirectResult = _overrideRedirectResult;
9697
9857
  }
9698
9858
  CordovaPopupRedirectResolver.prototype._initialize = function (auth) {
9699
9859
  return __awaiter(this, void 0, void 0, function () {
@@ -9853,5 +10013,5 @@ function generateNoEvent() {
9853
10013
  };
9854
10014
  }
9855
10015
 
9856
- export { fetchSignInMethodsForEmail as $, ActionCodeOperation as A, GithubAuthProvider as B, OAuthProvider as C, SAMLAuthProvider as D, EmailAuthCredential as E, FactorId as F, GoogleAuthProvider as G, signInAnonymously as H, signInWithCredential as I, linkWithCredential as J, reauthenticateWithCredential as K, signInWithCustomToken as L, sendPasswordResetEmail as M, confirmPasswordReset as N, OperationType as O, ProviderId as P, applyActionCode as Q, checkActionCode as R, SignInMethod as S, TwitterAuthProvider as T, verifyPasswordResetCode as U, createUserWithEmailAndPassword as V, signInWithEmailAndPassword as W, sendSignInLinkToEmail as X, isSignInWithEmailLink as Y, signInWithEmailLink as Z, _signInWithRedirect as _, _reauthenticateWithRedirect as a, sendEmailVerification as a0, verifyBeforeUpdateEmail as a1, ActionCodeURL as a2, parseActionCodeURL as a3, updateProfile as a4, updateEmail as a5, updatePassword as a6, getIdToken as a7, getIdTokenResult as a8, unlink as a9, _emulatorUrl as aA, _isChromeIOS as aB, _isFirefox as aC, _isIOSStandalone as aD, _isMobileBrowser as aE, _isSafari as aF, _isIOS as aG, _getRedirectResult as aH, _getRedirectUrl as aI, _setWindowLocation as aJ, AuthEventManager as aK, debugFail as aL, finalizeEnrollPhoneMfa as aM, _persistenceKeyName as aN, UserImpl as aO, _getInstance as aP, AuthImpl as aQ, _getClientVersion as aR, FetchProvider as aS, SAMLAuthCredential as aT, signInWithRedirect as aU, linkWithRedirect as aV, reauthenticateWithRedirect as aW, getAdditionalUserInfo as aa, reload as ab, getMultiFactorResolver as ac, multiFactor as ad, _performApiRequest as ae, _addTidIfNecessary as af, _createError as ag, _assert as ah, Delay as ai, _window as aj, _isHttpOrHttps as ak, _isWorker as al, _castAuth as am, sendPhoneVerificationCode as an, startEnrollPhoneMfa as ao, _assertLinkedStatus as ap, _link$1 as aq, debugAssert as ar, _generateEventId as as, AbstractPopupRedirectOperation as at, _assertInstanceOf as au, _withDefaultResolver as av, FederatedAuthProvider as aw, _fail as ax, _getProjectConfig as ay, _getCurrentUrl as az, _linkWithRedirect as b, indexedDBLocalPersistence as c, cordovaPopupRedirectResolver as d, browserLocalPersistence as e, browserSessionPersistence as f, getRedirectResult as g, onAuthStateChanged as h, initializeAuth as i, updateCurrentUser as j, signOut as k, deleteUser as l, debugErrorMap as m, AUTH_ERROR_CODES_MAP_DO_NOT_USE_INTERNALLY as n, onIdTokenChanged as o, prodErrorMap as p, connectAuthEmulator as q, registerAuth as r, setPersistence as s, AuthCredential as t, useDeviceLanguage as u, OAuthCredential as v, PhoneAuthCredential as w, inMemoryPersistence as x, EmailAuthProvider as y, FacebookAuthProvider as z };
9857
- //# sourceMappingURL=popup_redirect-fd81f644.js.map
10016
+ export { signInWithEmailLink as $, ActionCodeOperation as A, FacebookAuthProvider as B, GithubAuthProvider as C, OAuthProvider as D, EmailAuthCredential as E, FactorId as F, GoogleAuthProvider as G, SAMLAuthProvider as H, signInAnonymously as I, signInWithCredential as J, linkWithCredential as K, reauthenticateWithCredential as L, signInWithCustomToken as M, sendPasswordResetEmail as N, OperationType as O, ProviderId as P, confirmPasswordReset as Q, applyActionCode as R, SignInMethod as S, TwitterAuthProvider as T, checkActionCode as U, verifyPasswordResetCode as V, createUserWithEmailAndPassword as W, signInWithEmailAndPassword as X, sendSignInLinkToEmail as Y, isSignInWithEmailLink as Z, _signInWithRedirect as _, _reauthenticateWithRedirect as a, fetchSignInMethodsForEmail as a0, sendEmailVerification as a1, verifyBeforeUpdateEmail as a2, ActionCodeURL as a3, parseActionCodeURL as a4, updateProfile as a5, updateEmail as a6, updatePassword as a7, getIdToken as a8, getIdTokenResult as a9, _getCurrentUrl as aA, _emulatorUrl as aB, _isChromeIOS as aC, _isFirefox as aD, _isIOSStandalone as aE, _isMobileBrowser as aF, _isSafari as aG, _isIOS as aH, _getRedirectResult as aI, _overrideRedirectResult as aJ, _getRedirectUrl as aK, _setWindowLocation as aL, AuthEventManager as aM, debugFail as aN, finalizeEnrollPhoneMfa as aO, _persistenceKeyName as aP, UserImpl as aQ, _getInstance as aR, AuthImpl as aS, _getClientVersion as aT, FetchProvider as aU, SAMLAuthCredential as aV, signInWithRedirect as aW, linkWithRedirect as aX, reauthenticateWithRedirect as aY, unlink as aa, getAdditionalUserInfo as ab, reload as ac, getMultiFactorResolver as ad, multiFactor as ae, _performApiRequest as af, _addTidIfNecessary as ag, _createError as ah, _assert as ai, Delay as aj, _window as ak, _isHttpOrHttps as al, _isWorker as am, _castAuth as an, sendPhoneVerificationCode as ao, startEnrollPhoneMfa as ap, _assertLinkedStatus as aq, _link$1 as ar, debugAssert as as, _generateEventId as at, AbstractPopupRedirectOperation as au, _assertInstanceOf as av, _withDefaultResolver as aw, FederatedAuthProvider as ax, _fail as ay, _getProjectConfig as az, _linkWithRedirect as b, indexedDBLocalPersistence as c, cordovaPopupRedirectResolver as d, browserLocalPersistence as e, browserSessionPersistence as f, getRedirectResult as g, beforeAuthStateChanged as h, initializeAuth as i, onAuthStateChanged as j, updateCurrentUser as k, signOut as l, deleteUser as m, debugErrorMap as n, onIdTokenChanged as o, prodErrorMap as p, AUTH_ERROR_CODES_MAP_DO_NOT_USE_INTERNALLY as q, registerAuth as r, setPersistence as s, connectAuthEmulator as t, useDeviceLanguage as u, AuthCredential as v, OAuthCredential as w, PhoneAuthCredential as x, inMemoryPersistence as y, EmailAuthProvider as z };
10017
+ //# sourceMappingURL=popup_redirect-1228b67a.js.map