@firebase/auth-compat 0.5.15 → 0.5.16

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 (53) hide show
  1. package/dist/auth-compat/index.d.ts +50 -50
  2. package/dist/auth-compat/index.node.d.ts +24 -24
  3. package/dist/auth-compat/scripts/run_node_tests.d.ts +17 -17
  4. package/dist/auth-compat/src/auth.d.ts +72 -72
  5. package/dist/auth-compat/src/auth.test.d.ts +17 -17
  6. package/dist/auth-compat/src/persistence.d.ts +29 -29
  7. package/dist/auth-compat/src/phone_auth_provider.d.ts +29 -29
  8. package/dist/auth-compat/src/platform.d.ts +39 -39
  9. package/dist/auth-compat/src/popup_redirect.d.ts +34 -34
  10. package/dist/auth-compat/src/popup_redirect.test.d.ts +17 -17
  11. package/dist/auth-compat/src/recaptcha_verifier.d.ts +28 -28
  12. package/dist/auth-compat/src/user.d.ts +64 -64
  13. package/dist/auth-compat/src/user_credential.d.ts +20 -20
  14. package/dist/auth-compat/src/wrap.d.ts +26 -26
  15. package/dist/auth-compat/test/helpers/helpers.d.ts +24 -24
  16. package/dist/auth-compat/test/integration/flows/anonymous.test.d.ts +17 -17
  17. package/dist/auth-compat/test/integration/flows/custom.test.d.ts +17 -17
  18. package/dist/auth-compat/test/integration/flows/email.test.d.ts +17 -17
  19. package/dist/auth-compat/test/integration/flows/idp.test.d.ts +17 -17
  20. package/dist/auth-compat/test/integration/flows/oob.test.d.ts +17 -17
  21. package/dist/auth-compat/test/integration/flows/phone.test.d.ts +17 -17
  22. package/dist/esm/auth-compat/index.d.ts +50 -50
  23. package/dist/esm/auth-compat/index.node.d.ts +24 -24
  24. package/dist/esm/auth-compat/scripts/run_node_tests.d.ts +17 -17
  25. package/dist/esm/auth-compat/src/auth.d.ts +72 -72
  26. package/dist/esm/auth-compat/src/auth.test.d.ts +17 -17
  27. package/dist/esm/auth-compat/src/persistence.d.ts +29 -29
  28. package/dist/esm/auth-compat/src/phone_auth_provider.d.ts +29 -29
  29. package/dist/esm/auth-compat/src/platform.d.ts +39 -39
  30. package/dist/esm/auth-compat/src/popup_redirect.d.ts +34 -34
  31. package/dist/esm/auth-compat/src/popup_redirect.test.d.ts +17 -17
  32. package/dist/esm/auth-compat/src/recaptcha_verifier.d.ts +28 -28
  33. package/dist/esm/auth-compat/src/user.d.ts +64 -64
  34. package/dist/esm/auth-compat/src/user_credential.d.ts +20 -20
  35. package/dist/esm/auth-compat/src/wrap.d.ts +26 -26
  36. package/dist/esm/auth-compat/test/helpers/helpers.d.ts +24 -24
  37. package/dist/esm/auth-compat/test/integration/flows/anonymous.test.d.ts +17 -17
  38. package/dist/esm/auth-compat/test/integration/flows/custom.test.d.ts +17 -17
  39. package/dist/esm/auth-compat/test/integration/flows/email.test.d.ts +17 -17
  40. package/dist/esm/auth-compat/test/integration/flows/idp.test.d.ts +17 -17
  41. package/dist/esm/auth-compat/test/integration/flows/oob.test.d.ts +17 -17
  42. package/dist/esm/auth-compat/test/integration/flows/phone.test.d.ts +17 -17
  43. package/dist/esm/index.node.esm.js +993 -993
  44. package/dist/esm/index.node.esm.js.map +1 -1
  45. package/dist/firebase-auth.js +1 -1
  46. package/dist/firebase-auth.js.map +1 -1
  47. package/dist/index.cjs.js +977 -977
  48. package/dist/index.cjs.js.map +1 -1
  49. package/dist/index.esm2017.js +977 -977
  50. package/dist/index.esm2017.js.map +1 -1
  51. package/dist/index.node.cjs.js +993 -993
  52. package/dist/index.node.cjs.js.map +1 -1
  53. package/package.json +7 -7
@@ -5,1019 +5,1019 @@ import { Component } from '@firebase/component';
5
5
  import { isBrowserExtension, getUA, isReactNative, isNode, isIndexedDBAvailable, isIE, FirebaseError } from '@firebase/util';
6
6
 
7
7
  var name = "@firebase/auth-compat";
8
- var version = "0.5.15";
8
+ var version = "0.5.16";
9
9
 
10
- /**
11
- * @license
12
- * Copyright 2020 Google LLC
13
- *
14
- * Licensed under the Apache License, Version 2.0 (the "License");
15
- * you may not use this file except in compliance with the License.
16
- * You may obtain a copy of the License at
17
- *
18
- * http://www.apache.org/licenses/LICENSE-2.0
19
- *
20
- * Unless required by applicable law or agreed to in writing, software
21
- * distributed under the License is distributed on an "AS IS" BASIS,
22
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23
- * See the License for the specific language governing permissions and
24
- * limitations under the License.
25
- */
26
- const CORDOVA_ONDEVICEREADY_TIMEOUT_MS = 1000;
27
- function _getCurrentScheme() {
28
- var _a;
29
- return ((_a = self === null || self === void 0 ? void 0 : self.location) === null || _a === void 0 ? void 0 : _a.protocol) || null;
30
- }
31
- /**
32
- * @return {boolean} Whether the current environment is http or https.
33
- */
34
- function _isHttpOrHttps() {
35
- return _getCurrentScheme() === 'http:' || _getCurrentScheme() === 'https:';
36
- }
37
- /**
38
- * @param {?string=} ua The user agent.
39
- * @return {boolean} Whether the app is rendered in a mobile iOS or Android
40
- * Cordova environment.
41
- */
42
- function _isAndroidOrIosCordovaScheme(ua = getUA()) {
43
- return !!((_getCurrentScheme() === 'file:' ||
44
- _getCurrentScheme() === 'ionic:' ||
45
- _getCurrentScheme() === 'capacitor:') &&
46
- ua.toLowerCase().match(/iphone|ipad|ipod|android/));
47
- }
48
- /**
49
- * @return {boolean} Whether the environment is a native environment, where
50
- * CORS checks do not apply.
51
- */
52
- function _isNativeEnvironment() {
53
- return isReactNative() || isNode();
54
- }
55
- /**
56
- * Checks whether the user agent is IE11.
57
- * @return {boolean} True if it is IE11.
58
- */
59
- function _isIe11() {
60
- return isIE() && (document === null || document === void 0 ? void 0 : document.documentMode) === 11;
61
- }
62
- /**
63
- * Checks whether the user agent is Edge.
64
- * @param {string} userAgent The browser user agent string.
65
- * @return {boolean} True if it is Edge.
66
- */
67
- function _isEdge(ua = getUA()) {
68
- return /Edge\/\d+/.test(ua);
69
- }
70
- /**
71
- * @param {?string=} opt_userAgent The navigator user agent.
72
- * @return {boolean} Whether local storage is not synchronized between an iframe
73
- * and a popup of the same domain.
74
- */
75
- function _isLocalStorageNotSynchronized(ua = getUA()) {
76
- return _isIe11() || _isEdge(ua);
77
- }
78
- /** @return {boolean} Whether web storage is supported. */
79
- function _isWebStorageSupported() {
80
- try {
81
- const storage = self.localStorage;
82
- const key = exp._generateEventId();
83
- if (storage) {
84
- // setItem will throw an exception if we cannot access WebStorage (e.g.,
85
- // Safari in private mode).
86
- storage['setItem'](key, '1');
87
- storage['removeItem'](key);
88
- // For browsers where iframe web storage does not synchronize with a popup
89
- // of the same domain, indexedDB is used for persistent storage. These
90
- // browsers include IE11 and Edge.
91
- // Make sure it is supported (IE11 and Edge private mode does not support
92
- // that).
93
- if (_isLocalStorageNotSynchronized()) {
94
- // In such browsers, if indexedDB is not supported, an iframe cannot be
95
- // notified of the popup sign in result.
96
- return isIndexedDBAvailable();
97
- }
98
- return true;
99
- }
100
- }
101
- catch (e) {
102
- // localStorage is not available from a worker. Test availability of
103
- // indexedDB.
104
- return _isWorker() && isIndexedDBAvailable();
105
- }
106
- return false;
107
- }
108
- /**
109
- * @param {?Object=} global The optional global scope.
110
- * @return {boolean} Whether current environment is a worker.
111
- */
112
- function _isWorker() {
113
- // WorkerGlobalScope only defined in worker environment.
114
- return (typeof global !== 'undefined' &&
115
- 'WorkerGlobalScope' in global &&
116
- 'importScripts' in global);
117
- }
118
- function _isPopupRedirectSupported() {
119
- return ((_isHttpOrHttps() ||
120
- isBrowserExtension() ||
121
- _isAndroidOrIosCordovaScheme()) &&
122
- // React Native with remote debugging reports its location.protocol as
123
- // http.
124
- !_isNativeEnvironment() &&
125
- // Local storage has to be supported for browser popup and redirect
126
- // operations to work.
127
- _isWebStorageSupported() &&
128
- // DOM, popups and redirects are not supported within a worker.
129
- !_isWorker());
130
- }
131
- /** Quick check that indicates the platform *may* be Cordova */
132
- function _isLikelyCordova() {
133
- return _isAndroidOrIosCordovaScheme() && typeof document !== 'undefined';
134
- }
135
- async function _isCordova() {
136
- if (!_isLikelyCordova()) {
137
- return false;
138
- }
139
- return new Promise(resolve => {
140
- const timeoutId = setTimeout(() => {
141
- // We've waited long enough; the telltale Cordova event didn't happen
142
- resolve(false);
143
- }, CORDOVA_ONDEVICEREADY_TIMEOUT_MS);
144
- document.addEventListener('deviceready', () => {
145
- clearTimeout(timeoutId);
146
- resolve(true);
147
- });
148
- });
149
- }
150
- function _getSelfWindow() {
151
- return typeof window !== 'undefined' ? window : null;
10
+ /**
11
+ * @license
12
+ * Copyright 2020 Google LLC
13
+ *
14
+ * Licensed under the Apache License, Version 2.0 (the "License");
15
+ * you may not use this file except in compliance with the License.
16
+ * You may obtain a copy of the License at
17
+ *
18
+ * http://www.apache.org/licenses/LICENSE-2.0
19
+ *
20
+ * Unless required by applicable law or agreed to in writing, software
21
+ * distributed under the License is distributed on an "AS IS" BASIS,
22
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23
+ * See the License for the specific language governing permissions and
24
+ * limitations under the License.
25
+ */
26
+ const CORDOVA_ONDEVICEREADY_TIMEOUT_MS = 1000;
27
+ function _getCurrentScheme() {
28
+ var _a;
29
+ return ((_a = self === null || self === void 0 ? void 0 : self.location) === null || _a === void 0 ? void 0 : _a.protocol) || null;
30
+ }
31
+ /**
32
+ * @return {boolean} Whether the current environment is http or https.
33
+ */
34
+ function _isHttpOrHttps() {
35
+ return _getCurrentScheme() === 'http:' || _getCurrentScheme() === 'https:';
36
+ }
37
+ /**
38
+ * @param {?string=} ua The user agent.
39
+ * @return {boolean} Whether the app is rendered in a mobile iOS or Android
40
+ * Cordova environment.
41
+ */
42
+ function _isAndroidOrIosCordovaScheme(ua = getUA()) {
43
+ return !!((_getCurrentScheme() === 'file:' ||
44
+ _getCurrentScheme() === 'ionic:' ||
45
+ _getCurrentScheme() === 'capacitor:') &&
46
+ ua.toLowerCase().match(/iphone|ipad|ipod|android/));
47
+ }
48
+ /**
49
+ * @return {boolean} Whether the environment is a native environment, where
50
+ * CORS checks do not apply.
51
+ */
52
+ function _isNativeEnvironment() {
53
+ return isReactNative() || isNode();
54
+ }
55
+ /**
56
+ * Checks whether the user agent is IE11.
57
+ * @return {boolean} True if it is IE11.
58
+ */
59
+ function _isIe11() {
60
+ return isIE() && (document === null || document === void 0 ? void 0 : document.documentMode) === 11;
61
+ }
62
+ /**
63
+ * Checks whether the user agent is Edge.
64
+ * @param {string} userAgent The browser user agent string.
65
+ * @return {boolean} True if it is Edge.
66
+ */
67
+ function _isEdge(ua = getUA()) {
68
+ return /Edge\/\d+/.test(ua);
69
+ }
70
+ /**
71
+ * @param {?string=} opt_userAgent The navigator user agent.
72
+ * @return {boolean} Whether local storage is not synchronized between an iframe
73
+ * and a popup of the same domain.
74
+ */
75
+ function _isLocalStorageNotSynchronized(ua = getUA()) {
76
+ return _isIe11() || _isEdge(ua);
77
+ }
78
+ /** @return {boolean} Whether web storage is supported. */
79
+ function _isWebStorageSupported() {
80
+ try {
81
+ const storage = self.localStorage;
82
+ const key = exp._generateEventId();
83
+ if (storage) {
84
+ // setItem will throw an exception if we cannot access WebStorage (e.g.,
85
+ // Safari in private mode).
86
+ storage['setItem'](key, '1');
87
+ storage['removeItem'](key);
88
+ // For browsers where iframe web storage does not synchronize with a popup
89
+ // of the same domain, indexedDB is used for persistent storage. These
90
+ // browsers include IE11 and Edge.
91
+ // Make sure it is supported (IE11 and Edge private mode does not support
92
+ // that).
93
+ if (_isLocalStorageNotSynchronized()) {
94
+ // In such browsers, if indexedDB is not supported, an iframe cannot be
95
+ // notified of the popup sign in result.
96
+ return isIndexedDBAvailable();
97
+ }
98
+ return true;
99
+ }
100
+ }
101
+ catch (e) {
102
+ // localStorage is not available from a worker. Test availability of
103
+ // indexedDB.
104
+ return _isWorker() && isIndexedDBAvailable();
105
+ }
106
+ return false;
107
+ }
108
+ /**
109
+ * @param {?Object=} global The optional global scope.
110
+ * @return {boolean} Whether current environment is a worker.
111
+ */
112
+ function _isWorker() {
113
+ // WorkerGlobalScope only defined in worker environment.
114
+ return (typeof global !== 'undefined' &&
115
+ 'WorkerGlobalScope' in global &&
116
+ 'importScripts' in global);
117
+ }
118
+ function _isPopupRedirectSupported() {
119
+ return ((_isHttpOrHttps() ||
120
+ isBrowserExtension() ||
121
+ _isAndroidOrIosCordovaScheme()) &&
122
+ // React Native with remote debugging reports its location.protocol as
123
+ // http.
124
+ !_isNativeEnvironment() &&
125
+ // Local storage has to be supported for browser popup and redirect
126
+ // operations to work.
127
+ _isWebStorageSupported() &&
128
+ // DOM, popups and redirects are not supported within a worker.
129
+ !_isWorker());
130
+ }
131
+ /** Quick check that indicates the platform *may* be Cordova */
132
+ function _isLikelyCordova() {
133
+ return _isAndroidOrIosCordovaScheme() && typeof document !== 'undefined';
134
+ }
135
+ async function _isCordova() {
136
+ if (!_isLikelyCordova()) {
137
+ return false;
138
+ }
139
+ return new Promise(resolve => {
140
+ const timeoutId = setTimeout(() => {
141
+ // We've waited long enough; the telltale Cordova event didn't happen
142
+ resolve(false);
143
+ }, CORDOVA_ONDEVICEREADY_TIMEOUT_MS);
144
+ document.addEventListener('deviceready', () => {
145
+ clearTimeout(timeoutId);
146
+ resolve(true);
147
+ });
148
+ });
149
+ }
150
+ function _getSelfWindow() {
151
+ return typeof window !== 'undefined' ? window : null;
152
152
  }
153
153
 
154
- /**
155
- * @license
156
- * Copyright 2020 Google LLC
157
- *
158
- * Licensed under the Apache License, Version 2.0 (the "License");
159
- * you may not use this file except in compliance with the License.
160
- * You may obtain a copy of the License at
161
- *
162
- * http://www.apache.org/licenses/LICENSE-2.0
163
- *
164
- * Unless required by applicable law or agreed to in writing, software
165
- * distributed under the License is distributed on an "AS IS" BASIS,
166
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
167
- * See the License for the specific language governing permissions and
168
- * limitations under the License.
169
- */
170
- const Persistence = {
171
- LOCAL: 'local',
172
- NONE: 'none',
173
- SESSION: 'session'
174
- };
175
- const _assert$3 = exp._assert;
176
- const PERSISTENCE_KEY = 'persistence';
177
- /**
178
- * Validates that an argument is a valid persistence value. If an invalid type
179
- * is specified, an error is thrown synchronously.
180
- */
181
- function _validatePersistenceArgument(auth, persistence) {
182
- _assert$3(Object.values(Persistence).includes(persistence), auth, "invalid-persistence-type" /* exp.AuthErrorCode.INVALID_PERSISTENCE */);
183
- // Validate if the specified type is supported in the current environment.
184
- if (isReactNative()) {
185
- // This is only supported in a browser.
186
- _assert$3(persistence !== Persistence.SESSION, auth, "unsupported-persistence-type" /* exp.AuthErrorCode.UNSUPPORTED_PERSISTENCE */);
187
- return;
188
- }
189
- if (isNode()) {
190
- // Only none is supported in Node.js.
191
- _assert$3(persistence === Persistence.NONE, auth, "unsupported-persistence-type" /* exp.AuthErrorCode.UNSUPPORTED_PERSISTENCE */);
192
- return;
193
- }
194
- if (_isWorker()) {
195
- // In a worker environment, either LOCAL or NONE are supported.
196
- // If indexedDB not supported and LOCAL provided, throw an error
197
- _assert$3(persistence === Persistence.NONE ||
198
- (persistence === Persistence.LOCAL && isIndexedDBAvailable()), auth, "unsupported-persistence-type" /* exp.AuthErrorCode.UNSUPPORTED_PERSISTENCE */);
199
- return;
200
- }
201
- // This is restricted by what the browser supports.
202
- _assert$3(persistence === Persistence.NONE || _isWebStorageSupported(), auth, "unsupported-persistence-type" /* exp.AuthErrorCode.UNSUPPORTED_PERSISTENCE */);
203
- }
204
- async function _savePersistenceForRedirect(auth) {
205
- await auth._initializationPromise;
206
- const session = getSessionStorageIfAvailable();
207
- const key = exp._persistenceKeyName(PERSISTENCE_KEY, auth.config.apiKey, auth.name);
208
- if (session) {
209
- session.setItem(key, auth._getPersistence());
210
- }
211
- }
212
- function _getPersistencesFromRedirect(apiKey, appName) {
213
- const session = getSessionStorageIfAvailable();
214
- if (!session) {
215
- return [];
216
- }
217
- const key = exp._persistenceKeyName(PERSISTENCE_KEY, apiKey, appName);
218
- const persistence = session.getItem(key);
219
- switch (persistence) {
220
- case Persistence.NONE:
221
- return [exp.inMemoryPersistence];
222
- case Persistence.LOCAL:
223
- return [exp.indexedDBLocalPersistence, exp.browserSessionPersistence];
224
- case Persistence.SESSION:
225
- return [exp.browserSessionPersistence];
226
- default:
227
- return [];
228
- }
229
- }
230
- /** Returns session storage, or null if the property access errors */
231
- function getSessionStorageIfAvailable() {
232
- var _a;
233
- try {
234
- return ((_a = _getSelfWindow()) === null || _a === void 0 ? void 0 : _a.sessionStorage) || null;
235
- }
236
- catch (e) {
237
- return null;
238
- }
154
+ /**
155
+ * @license
156
+ * Copyright 2020 Google LLC
157
+ *
158
+ * Licensed under the Apache License, Version 2.0 (the "License");
159
+ * you may not use this file except in compliance with the License.
160
+ * You may obtain a copy of the License at
161
+ *
162
+ * http://www.apache.org/licenses/LICENSE-2.0
163
+ *
164
+ * Unless required by applicable law or agreed to in writing, software
165
+ * distributed under the License is distributed on an "AS IS" BASIS,
166
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
167
+ * See the License for the specific language governing permissions and
168
+ * limitations under the License.
169
+ */
170
+ const Persistence = {
171
+ LOCAL: 'local',
172
+ NONE: 'none',
173
+ SESSION: 'session'
174
+ };
175
+ const _assert$3 = exp._assert;
176
+ const PERSISTENCE_KEY = 'persistence';
177
+ /**
178
+ * Validates that an argument is a valid persistence value. If an invalid type
179
+ * is specified, an error is thrown synchronously.
180
+ */
181
+ function _validatePersistenceArgument(auth, persistence) {
182
+ _assert$3(Object.values(Persistence).includes(persistence), auth, "invalid-persistence-type" /* exp.AuthErrorCode.INVALID_PERSISTENCE */);
183
+ // Validate if the specified type is supported in the current environment.
184
+ if (isReactNative()) {
185
+ // This is only supported in a browser.
186
+ _assert$3(persistence !== Persistence.SESSION, auth, "unsupported-persistence-type" /* exp.AuthErrorCode.UNSUPPORTED_PERSISTENCE */);
187
+ return;
188
+ }
189
+ if (isNode()) {
190
+ // Only none is supported in Node.js.
191
+ _assert$3(persistence === Persistence.NONE, auth, "unsupported-persistence-type" /* exp.AuthErrorCode.UNSUPPORTED_PERSISTENCE */);
192
+ return;
193
+ }
194
+ if (_isWorker()) {
195
+ // In a worker environment, either LOCAL or NONE are supported.
196
+ // If indexedDB not supported and LOCAL provided, throw an error
197
+ _assert$3(persistence === Persistence.NONE ||
198
+ (persistence === Persistence.LOCAL && isIndexedDBAvailable()), auth, "unsupported-persistence-type" /* exp.AuthErrorCode.UNSUPPORTED_PERSISTENCE */);
199
+ return;
200
+ }
201
+ // This is restricted by what the browser supports.
202
+ _assert$3(persistence === Persistence.NONE || _isWebStorageSupported(), auth, "unsupported-persistence-type" /* exp.AuthErrorCode.UNSUPPORTED_PERSISTENCE */);
203
+ }
204
+ async function _savePersistenceForRedirect(auth) {
205
+ await auth._initializationPromise;
206
+ const session = getSessionStorageIfAvailable();
207
+ const key = exp._persistenceKeyName(PERSISTENCE_KEY, auth.config.apiKey, auth.name);
208
+ if (session) {
209
+ session.setItem(key, auth._getPersistence());
210
+ }
211
+ }
212
+ function _getPersistencesFromRedirect(apiKey, appName) {
213
+ const session = getSessionStorageIfAvailable();
214
+ if (!session) {
215
+ return [];
216
+ }
217
+ const key = exp._persistenceKeyName(PERSISTENCE_KEY, apiKey, appName);
218
+ const persistence = session.getItem(key);
219
+ switch (persistence) {
220
+ case Persistence.NONE:
221
+ return [exp.inMemoryPersistence];
222
+ case Persistence.LOCAL:
223
+ return [exp.indexedDBLocalPersistence, exp.browserSessionPersistence];
224
+ case Persistence.SESSION:
225
+ return [exp.browserSessionPersistence];
226
+ default:
227
+ return [];
228
+ }
229
+ }
230
+ /** Returns session storage, or null if the property access errors */
231
+ function getSessionStorageIfAvailable() {
232
+ var _a;
233
+ try {
234
+ return ((_a = _getSelfWindow()) === null || _a === void 0 ? void 0 : _a.sessionStorage) || null;
235
+ }
236
+ catch (e) {
237
+ return null;
238
+ }
239
239
  }
240
240
 
241
- /**
242
- * @license
243
- * Copyright 2020 Google LLC
244
- *
245
- * Licensed under the Apache License, Version 2.0 (the "License");
246
- * you may not use this file except in compliance with the License.
247
- * You may obtain a copy of the License at
248
- *
249
- * http://www.apache.org/licenses/LICENSE-2.0
250
- *
251
- * Unless required by applicable law or agreed to in writing, software
252
- * distributed under the License is distributed on an "AS IS" BASIS,
253
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
254
- * See the License for the specific language governing permissions and
255
- * limitations under the License.
256
- */
257
- const _assert$2 = exp._assert;
258
- /** Platform-agnostic popup-redirect resolver */
259
- class CompatPopupRedirectResolver {
260
- constructor() {
261
- // Create both resolvers for dynamic resolution later
262
- this.browserResolver = exp._getInstance(exp.browserPopupRedirectResolver);
263
- this.cordovaResolver = exp._getInstance(exp.cordovaPopupRedirectResolver);
264
- // The actual resolver in use: either browserResolver or cordovaResolver.
265
- this.underlyingResolver = null;
266
- this._redirectPersistence = exp.browserSessionPersistence;
267
- this._completeRedirectFn = exp._getRedirectResult;
268
- this._overrideRedirectResult = exp._overrideRedirectResult;
269
- }
270
- async _initialize(auth) {
271
- await this.selectUnderlyingResolver();
272
- return this.assertedUnderlyingResolver._initialize(auth);
273
- }
274
- async _openPopup(auth, provider, authType, eventId) {
275
- await this.selectUnderlyingResolver();
276
- return this.assertedUnderlyingResolver._openPopup(auth, provider, authType, eventId);
277
- }
278
- async _openRedirect(auth, provider, authType, eventId) {
279
- await this.selectUnderlyingResolver();
280
- return this.assertedUnderlyingResolver._openRedirect(auth, provider, authType, eventId);
281
- }
282
- _isIframeWebStorageSupported(auth, cb) {
283
- this.assertedUnderlyingResolver._isIframeWebStorageSupported(auth, cb);
284
- }
285
- _originValidation(auth) {
286
- return this.assertedUnderlyingResolver._originValidation(auth);
287
- }
288
- get _shouldInitProactively() {
289
- return _isLikelyCordova() || this.browserResolver._shouldInitProactively;
290
- }
291
- get assertedUnderlyingResolver() {
292
- _assert$2(this.underlyingResolver, "internal-error" /* exp.AuthErrorCode.INTERNAL_ERROR */);
293
- return this.underlyingResolver;
294
- }
295
- async selectUnderlyingResolver() {
296
- if (this.underlyingResolver) {
297
- return;
298
- }
299
- // We haven't yet determined whether or not we're in Cordova; go ahead
300
- // and determine that state now.
301
- const isCordova = await _isCordova();
302
- this.underlyingResolver = isCordova
303
- ? this.cordovaResolver
304
- : this.browserResolver;
305
- }
241
+ /**
242
+ * @license
243
+ * Copyright 2020 Google LLC
244
+ *
245
+ * Licensed under the Apache License, Version 2.0 (the "License");
246
+ * you may not use this file except in compliance with the License.
247
+ * You may obtain a copy of the License at
248
+ *
249
+ * http://www.apache.org/licenses/LICENSE-2.0
250
+ *
251
+ * Unless required by applicable law or agreed to in writing, software
252
+ * distributed under the License is distributed on an "AS IS" BASIS,
253
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
254
+ * See the License for the specific language governing permissions and
255
+ * limitations under the License.
256
+ */
257
+ const _assert$2 = exp._assert;
258
+ /** Platform-agnostic popup-redirect resolver */
259
+ class CompatPopupRedirectResolver {
260
+ constructor() {
261
+ // Create both resolvers for dynamic resolution later
262
+ this.browserResolver = exp._getInstance(exp.browserPopupRedirectResolver);
263
+ this.cordovaResolver = exp._getInstance(exp.cordovaPopupRedirectResolver);
264
+ // The actual resolver in use: either browserResolver or cordovaResolver.
265
+ this.underlyingResolver = null;
266
+ this._redirectPersistence = exp.browserSessionPersistence;
267
+ this._completeRedirectFn = exp._getRedirectResult;
268
+ this._overrideRedirectResult = exp._overrideRedirectResult;
269
+ }
270
+ async _initialize(auth) {
271
+ await this.selectUnderlyingResolver();
272
+ return this.assertedUnderlyingResolver._initialize(auth);
273
+ }
274
+ async _openPopup(auth, provider, authType, eventId) {
275
+ await this.selectUnderlyingResolver();
276
+ return this.assertedUnderlyingResolver._openPopup(auth, provider, authType, eventId);
277
+ }
278
+ async _openRedirect(auth, provider, authType, eventId) {
279
+ await this.selectUnderlyingResolver();
280
+ return this.assertedUnderlyingResolver._openRedirect(auth, provider, authType, eventId);
281
+ }
282
+ _isIframeWebStorageSupported(auth, cb) {
283
+ this.assertedUnderlyingResolver._isIframeWebStorageSupported(auth, cb);
284
+ }
285
+ _originValidation(auth) {
286
+ return this.assertedUnderlyingResolver._originValidation(auth);
287
+ }
288
+ get _shouldInitProactively() {
289
+ return _isLikelyCordova() || this.browserResolver._shouldInitProactively;
290
+ }
291
+ get assertedUnderlyingResolver() {
292
+ _assert$2(this.underlyingResolver, "internal-error" /* exp.AuthErrorCode.INTERNAL_ERROR */);
293
+ return this.underlyingResolver;
294
+ }
295
+ async selectUnderlyingResolver() {
296
+ if (this.underlyingResolver) {
297
+ return;
298
+ }
299
+ // We haven't yet determined whether or not we're in Cordova; go ahead
300
+ // and determine that state now.
301
+ const isCordova = await _isCordova();
302
+ this.underlyingResolver = isCordova
303
+ ? this.cordovaResolver
304
+ : this.browserResolver;
305
+ }
306
306
  }
307
307
 
308
- /**
309
- * @license
310
- * Copyright 2020 Google LLC
311
- *
312
- * Licensed under the Apache License, Version 2.0 (the "License");
313
- * you may not use this file except in compliance with the License.
314
- * You may obtain a copy of the License at
315
- *
316
- * http://www.apache.org/licenses/LICENSE-2.0
317
- *
318
- * Unless required by applicable law or agreed to in writing, software
319
- * distributed under the License is distributed on an "AS IS" BASIS,
320
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
321
- * See the License for the specific language governing permissions and
322
- * limitations under the License.
323
- */
324
- function unwrap(object) {
325
- return object.unwrap();
326
- }
327
- function wrapped(object) {
328
- return object.wrapped();
308
+ /**
309
+ * @license
310
+ * Copyright 2020 Google LLC
311
+ *
312
+ * Licensed under the Apache License, Version 2.0 (the "License");
313
+ * you may not use this file except in compliance with the License.
314
+ * You may obtain a copy of the License at
315
+ *
316
+ * http://www.apache.org/licenses/LICENSE-2.0
317
+ *
318
+ * Unless required by applicable law or agreed to in writing, software
319
+ * distributed under the License is distributed on an "AS IS" BASIS,
320
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
321
+ * See the License for the specific language governing permissions and
322
+ * limitations under the License.
323
+ */
324
+ function unwrap(object) {
325
+ return object.unwrap();
326
+ }
327
+ function wrapped(object) {
328
+ return object.wrapped();
329
329
  }
330
330
 
331
- /**
332
- * @license
333
- * Copyright 2020 Google LLC
334
- *
335
- * Licensed under the Apache License, Version 2.0 (the "License");
336
- * you may not use this file except in compliance with the License.
337
- * You may obtain a copy of the License at
338
- *
339
- * http://www.apache.org/licenses/LICENSE-2.0
340
- *
341
- * Unless required by applicable law or agreed to in writing, software
342
- * distributed under the License is distributed on an "AS IS" BASIS,
343
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
344
- * See the License for the specific language governing permissions and
345
- * limitations under the License.
346
- */
347
- function credentialFromResponse(userCredential) {
348
- return credentialFromObject(userCredential);
349
- }
350
- function attachExtraErrorFields(auth, e) {
351
- var _a;
352
- // The response contains all fields from the server which may or may not
353
- // actually match the underlying type
354
- const response = (_a = e.customData) === null || _a === void 0 ? void 0 : _a._tokenResponse;
355
- if ((e === null || e === void 0 ? void 0 : e.code) === 'auth/multi-factor-auth-required') {
356
- const mfaErr = e;
357
- mfaErr.resolver = new MultiFactorResolver(auth, exp.getMultiFactorResolver(auth, e));
358
- }
359
- else if (response) {
360
- const credential = credentialFromObject(e);
361
- const credErr = e;
362
- if (credential) {
363
- credErr.credential = credential;
364
- credErr.tenantId = response.tenantId || undefined;
365
- credErr.email = response.email || undefined;
366
- credErr.phoneNumber = response.phoneNumber || undefined;
367
- }
368
- }
369
- }
370
- function credentialFromObject(object) {
371
- const { _tokenResponse } = (object instanceof FirebaseError ? object.customData : object);
372
- if (!_tokenResponse) {
373
- return null;
374
- }
375
- // Handle phone Auth credential responses, as they have a different format
376
- // from other backend responses (i.e. no providerId). This is also only the
377
- // case for user credentials (does not work for errors).
378
- if (!(object instanceof FirebaseError)) {
379
- if ('temporaryProof' in _tokenResponse && 'phoneNumber' in _tokenResponse) {
380
- return exp.PhoneAuthProvider.credentialFromResult(object);
381
- }
382
- }
383
- const providerId = _tokenResponse.providerId;
384
- // Email and password is not supported as there is no situation where the
385
- // server would return the password to the client.
386
- if (!providerId || providerId === exp.ProviderId.PASSWORD) {
387
- return null;
388
- }
389
- let provider;
390
- switch (providerId) {
391
- case exp.ProviderId.GOOGLE:
392
- provider = exp.GoogleAuthProvider;
393
- break;
394
- case exp.ProviderId.FACEBOOK:
395
- provider = exp.FacebookAuthProvider;
396
- break;
397
- case exp.ProviderId.GITHUB:
398
- provider = exp.GithubAuthProvider;
399
- break;
400
- case exp.ProviderId.TWITTER:
401
- provider = exp.TwitterAuthProvider;
402
- break;
403
- default:
404
- const { oauthIdToken, oauthAccessToken, oauthTokenSecret, pendingToken, nonce } = _tokenResponse;
405
- if (!oauthAccessToken &&
406
- !oauthTokenSecret &&
407
- !oauthIdToken &&
408
- !pendingToken) {
409
- return null;
410
- }
411
- // TODO(avolkovi): uncomment this and get it working with SAML & OIDC
412
- if (pendingToken) {
413
- if (providerId.startsWith('saml.')) {
414
- return exp.SAMLAuthCredential._create(providerId, pendingToken);
415
- }
416
- else {
417
- // OIDC and non-default providers excluding Twitter.
418
- return exp.OAuthCredential._fromParams({
419
- providerId,
420
- signInMethod: providerId,
421
- pendingToken,
422
- idToken: oauthIdToken,
423
- accessToken: oauthAccessToken
424
- });
425
- }
426
- }
427
- return new exp.OAuthProvider(providerId).credential({
428
- idToken: oauthIdToken,
429
- accessToken: oauthAccessToken,
430
- rawNonce: nonce
431
- });
432
- }
433
- return object instanceof FirebaseError
434
- ? provider.credentialFromError(object)
435
- : provider.credentialFromResult(object);
436
- }
437
- function convertCredential(auth, credentialPromise) {
438
- return credentialPromise
439
- .catch(e => {
440
- if (e instanceof FirebaseError) {
441
- attachExtraErrorFields(auth, e);
442
- }
443
- throw e;
444
- })
445
- .then(credential => {
446
- const operationType = credential.operationType;
447
- const user = credential.user;
448
- return {
449
- operationType,
450
- credential: credentialFromResponse(credential),
451
- additionalUserInfo: exp.getAdditionalUserInfo(credential),
452
- user: User.getOrCreate(user)
453
- };
454
- });
455
- }
456
- async function convertConfirmationResult(auth, confirmationResultPromise) {
457
- const confirmationResultExp = await confirmationResultPromise;
458
- return {
459
- verificationId: confirmationResultExp.verificationId,
460
- confirm: (verificationCode) => convertCredential(auth, confirmationResultExp.confirm(verificationCode))
461
- };
462
- }
463
- class MultiFactorResolver {
464
- constructor(auth, resolver) {
465
- this.resolver = resolver;
466
- this.auth = wrapped(auth);
467
- }
468
- get session() {
469
- return this.resolver.session;
470
- }
471
- get hints() {
472
- return this.resolver.hints;
473
- }
474
- resolveSignIn(assertion) {
475
- return convertCredential(unwrap(this.auth), this.resolver.resolveSignIn(assertion));
476
- }
331
+ /**
332
+ * @license
333
+ * Copyright 2020 Google LLC
334
+ *
335
+ * Licensed under the Apache License, Version 2.0 (the "License");
336
+ * you may not use this file except in compliance with the License.
337
+ * You may obtain a copy of the License at
338
+ *
339
+ * http://www.apache.org/licenses/LICENSE-2.0
340
+ *
341
+ * Unless required by applicable law or agreed to in writing, software
342
+ * distributed under the License is distributed on an "AS IS" BASIS,
343
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
344
+ * See the License for the specific language governing permissions and
345
+ * limitations under the License.
346
+ */
347
+ function credentialFromResponse(userCredential) {
348
+ return credentialFromObject(userCredential);
349
+ }
350
+ function attachExtraErrorFields(auth, e) {
351
+ var _a;
352
+ // The response contains all fields from the server which may or may not
353
+ // actually match the underlying type
354
+ const response = (_a = e.customData) === null || _a === void 0 ? void 0 : _a._tokenResponse;
355
+ if ((e === null || e === void 0 ? void 0 : e.code) === 'auth/multi-factor-auth-required') {
356
+ const mfaErr = e;
357
+ mfaErr.resolver = new MultiFactorResolver(auth, exp.getMultiFactorResolver(auth, e));
358
+ }
359
+ else if (response) {
360
+ const credential = credentialFromObject(e);
361
+ const credErr = e;
362
+ if (credential) {
363
+ credErr.credential = credential;
364
+ credErr.tenantId = response.tenantId || undefined;
365
+ credErr.email = response.email || undefined;
366
+ credErr.phoneNumber = response.phoneNumber || undefined;
367
+ }
368
+ }
369
+ }
370
+ function credentialFromObject(object) {
371
+ const { _tokenResponse } = (object instanceof FirebaseError ? object.customData : object);
372
+ if (!_tokenResponse) {
373
+ return null;
374
+ }
375
+ // Handle phone Auth credential responses, as they have a different format
376
+ // from other backend responses (i.e. no providerId). This is also only the
377
+ // case for user credentials (does not work for errors).
378
+ if (!(object instanceof FirebaseError)) {
379
+ if ('temporaryProof' in _tokenResponse && 'phoneNumber' in _tokenResponse) {
380
+ return exp.PhoneAuthProvider.credentialFromResult(object);
381
+ }
382
+ }
383
+ const providerId = _tokenResponse.providerId;
384
+ // Email and password is not supported as there is no situation where the
385
+ // server would return the password to the client.
386
+ if (!providerId || providerId === exp.ProviderId.PASSWORD) {
387
+ return null;
388
+ }
389
+ let provider;
390
+ switch (providerId) {
391
+ case exp.ProviderId.GOOGLE:
392
+ provider = exp.GoogleAuthProvider;
393
+ break;
394
+ case exp.ProviderId.FACEBOOK:
395
+ provider = exp.FacebookAuthProvider;
396
+ break;
397
+ case exp.ProviderId.GITHUB:
398
+ provider = exp.GithubAuthProvider;
399
+ break;
400
+ case exp.ProviderId.TWITTER:
401
+ provider = exp.TwitterAuthProvider;
402
+ break;
403
+ default:
404
+ const { oauthIdToken, oauthAccessToken, oauthTokenSecret, pendingToken, nonce } = _tokenResponse;
405
+ if (!oauthAccessToken &&
406
+ !oauthTokenSecret &&
407
+ !oauthIdToken &&
408
+ !pendingToken) {
409
+ return null;
410
+ }
411
+ // TODO(avolkovi): uncomment this and get it working with SAML & OIDC
412
+ if (pendingToken) {
413
+ if (providerId.startsWith('saml.')) {
414
+ return exp.SAMLAuthCredential._create(providerId, pendingToken);
415
+ }
416
+ else {
417
+ // OIDC and non-default providers excluding Twitter.
418
+ return exp.OAuthCredential._fromParams({
419
+ providerId,
420
+ signInMethod: providerId,
421
+ pendingToken,
422
+ idToken: oauthIdToken,
423
+ accessToken: oauthAccessToken
424
+ });
425
+ }
426
+ }
427
+ return new exp.OAuthProvider(providerId).credential({
428
+ idToken: oauthIdToken,
429
+ accessToken: oauthAccessToken,
430
+ rawNonce: nonce
431
+ });
432
+ }
433
+ return object instanceof FirebaseError
434
+ ? provider.credentialFromError(object)
435
+ : provider.credentialFromResult(object);
436
+ }
437
+ function convertCredential(auth, credentialPromise) {
438
+ return credentialPromise
439
+ .catch(e => {
440
+ if (e instanceof FirebaseError) {
441
+ attachExtraErrorFields(auth, e);
442
+ }
443
+ throw e;
444
+ })
445
+ .then(credential => {
446
+ const operationType = credential.operationType;
447
+ const user = credential.user;
448
+ return {
449
+ operationType,
450
+ credential: credentialFromResponse(credential),
451
+ additionalUserInfo: exp.getAdditionalUserInfo(credential),
452
+ user: User.getOrCreate(user)
453
+ };
454
+ });
455
+ }
456
+ async function convertConfirmationResult(auth, confirmationResultPromise) {
457
+ const confirmationResultExp = await confirmationResultPromise;
458
+ return {
459
+ verificationId: confirmationResultExp.verificationId,
460
+ confirm: (verificationCode) => convertCredential(auth, confirmationResultExp.confirm(verificationCode))
461
+ };
462
+ }
463
+ class MultiFactorResolver {
464
+ constructor(auth, resolver) {
465
+ this.resolver = resolver;
466
+ this.auth = wrapped(auth);
467
+ }
468
+ get session() {
469
+ return this.resolver.session;
470
+ }
471
+ get hints() {
472
+ return this.resolver.hints;
473
+ }
474
+ resolveSignIn(assertion) {
475
+ return convertCredential(unwrap(this.auth), this.resolver.resolveSignIn(assertion));
476
+ }
477
477
  }
478
478
 
479
- /**
480
- * @license
481
- * Copyright 2020 Google LLC
482
- *
483
- * Licensed under the Apache License, Version 2.0 (the "License");
484
- * you may not use this file except in compliance with the License.
485
- * You may obtain a copy of the License at
486
- *
487
- * http://www.apache.org/licenses/LICENSE-2.0
488
- *
489
- * Unless required by applicable law or agreed to in writing, software
490
- * distributed under the License is distributed on an "AS IS" BASIS,
491
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
492
- * See the License for the specific language governing permissions and
493
- * limitations under the License.
494
- */
495
- class User {
496
- constructor(_delegate) {
497
- this._delegate = _delegate;
498
- this.multiFactor = exp.multiFactor(_delegate);
499
- }
500
- static getOrCreate(user) {
501
- if (!User.USER_MAP.has(user)) {
502
- User.USER_MAP.set(user, new User(user));
503
- }
504
- return User.USER_MAP.get(user);
505
- }
506
- delete() {
507
- return this._delegate.delete();
508
- }
509
- reload() {
510
- return this._delegate.reload();
511
- }
512
- toJSON() {
513
- return this._delegate.toJSON();
514
- }
515
- getIdTokenResult(forceRefresh) {
516
- return this._delegate.getIdTokenResult(forceRefresh);
517
- }
518
- getIdToken(forceRefresh) {
519
- return this._delegate.getIdToken(forceRefresh);
520
- }
521
- linkAndRetrieveDataWithCredential(credential) {
522
- return this.linkWithCredential(credential);
523
- }
524
- async linkWithCredential(credential) {
525
- return convertCredential(this.auth, exp.linkWithCredential(this._delegate, credential));
526
- }
527
- async linkWithPhoneNumber(phoneNumber, applicationVerifier) {
528
- return convertConfirmationResult(this.auth, exp.linkWithPhoneNumber(this._delegate, phoneNumber, applicationVerifier));
529
- }
530
- async linkWithPopup(provider) {
531
- return convertCredential(this.auth, exp.linkWithPopup(this._delegate, provider, CompatPopupRedirectResolver));
532
- }
533
- async linkWithRedirect(provider) {
534
- await _savePersistenceForRedirect(exp._castAuth(this.auth));
535
- return exp.linkWithRedirect(this._delegate, provider, CompatPopupRedirectResolver);
536
- }
537
- reauthenticateAndRetrieveDataWithCredential(credential) {
538
- return this.reauthenticateWithCredential(credential);
539
- }
540
- async reauthenticateWithCredential(credential) {
541
- return convertCredential(this.auth, exp.reauthenticateWithCredential(this._delegate, credential));
542
- }
543
- reauthenticateWithPhoneNumber(phoneNumber, applicationVerifier) {
544
- return convertConfirmationResult(this.auth, exp.reauthenticateWithPhoneNumber(this._delegate, phoneNumber, applicationVerifier));
545
- }
546
- reauthenticateWithPopup(provider) {
547
- return convertCredential(this.auth, exp.reauthenticateWithPopup(this._delegate, provider, CompatPopupRedirectResolver));
548
- }
549
- async reauthenticateWithRedirect(provider) {
550
- await _savePersistenceForRedirect(exp._castAuth(this.auth));
551
- return exp.reauthenticateWithRedirect(this._delegate, provider, CompatPopupRedirectResolver);
552
- }
553
- sendEmailVerification(actionCodeSettings) {
554
- return exp.sendEmailVerification(this._delegate, actionCodeSettings);
555
- }
556
- async unlink(providerId) {
557
- await exp.unlink(this._delegate, providerId);
558
- return this;
559
- }
560
- updateEmail(newEmail) {
561
- return exp.updateEmail(this._delegate, newEmail);
562
- }
563
- updatePassword(newPassword) {
564
- return exp.updatePassword(this._delegate, newPassword);
565
- }
566
- updatePhoneNumber(phoneCredential) {
567
- return exp.updatePhoneNumber(this._delegate, phoneCredential);
568
- }
569
- updateProfile(profile) {
570
- return exp.updateProfile(this._delegate, profile);
571
- }
572
- verifyBeforeUpdateEmail(newEmail, actionCodeSettings) {
573
- return exp.verifyBeforeUpdateEmail(this._delegate, newEmail, actionCodeSettings);
574
- }
575
- get emailVerified() {
576
- return this._delegate.emailVerified;
577
- }
578
- get isAnonymous() {
579
- return this._delegate.isAnonymous;
580
- }
581
- get metadata() {
582
- return this._delegate.metadata;
583
- }
584
- get phoneNumber() {
585
- return this._delegate.phoneNumber;
586
- }
587
- get providerData() {
588
- return this._delegate.providerData;
589
- }
590
- get refreshToken() {
591
- return this._delegate.refreshToken;
592
- }
593
- get tenantId() {
594
- return this._delegate.tenantId;
595
- }
596
- get displayName() {
597
- return this._delegate.displayName;
598
- }
599
- get email() {
600
- return this._delegate.email;
601
- }
602
- get photoURL() {
603
- return this._delegate.photoURL;
604
- }
605
- get providerId() {
606
- return this._delegate.providerId;
607
- }
608
- get uid() {
609
- return this._delegate.uid;
610
- }
611
- get auth() {
612
- return this._delegate.auth;
613
- }
614
- }
615
- // Maintain a map so that there's always a 1:1 mapping between new User and
616
- // legacy compat users
479
+ /**
480
+ * @license
481
+ * Copyright 2020 Google LLC
482
+ *
483
+ * Licensed under the Apache License, Version 2.0 (the "License");
484
+ * you may not use this file except in compliance with the License.
485
+ * You may obtain a copy of the License at
486
+ *
487
+ * http://www.apache.org/licenses/LICENSE-2.0
488
+ *
489
+ * Unless required by applicable law or agreed to in writing, software
490
+ * distributed under the License is distributed on an "AS IS" BASIS,
491
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
492
+ * See the License for the specific language governing permissions and
493
+ * limitations under the License.
494
+ */
495
+ class User {
496
+ constructor(_delegate) {
497
+ this._delegate = _delegate;
498
+ this.multiFactor = exp.multiFactor(_delegate);
499
+ }
500
+ static getOrCreate(user) {
501
+ if (!User.USER_MAP.has(user)) {
502
+ User.USER_MAP.set(user, new User(user));
503
+ }
504
+ return User.USER_MAP.get(user);
505
+ }
506
+ delete() {
507
+ return this._delegate.delete();
508
+ }
509
+ reload() {
510
+ return this._delegate.reload();
511
+ }
512
+ toJSON() {
513
+ return this._delegate.toJSON();
514
+ }
515
+ getIdTokenResult(forceRefresh) {
516
+ return this._delegate.getIdTokenResult(forceRefresh);
517
+ }
518
+ getIdToken(forceRefresh) {
519
+ return this._delegate.getIdToken(forceRefresh);
520
+ }
521
+ linkAndRetrieveDataWithCredential(credential) {
522
+ return this.linkWithCredential(credential);
523
+ }
524
+ async linkWithCredential(credential) {
525
+ return convertCredential(this.auth, exp.linkWithCredential(this._delegate, credential));
526
+ }
527
+ async linkWithPhoneNumber(phoneNumber, applicationVerifier) {
528
+ return convertConfirmationResult(this.auth, exp.linkWithPhoneNumber(this._delegate, phoneNumber, applicationVerifier));
529
+ }
530
+ async linkWithPopup(provider) {
531
+ return convertCredential(this.auth, exp.linkWithPopup(this._delegate, provider, CompatPopupRedirectResolver));
532
+ }
533
+ async linkWithRedirect(provider) {
534
+ await _savePersistenceForRedirect(exp._castAuth(this.auth));
535
+ return exp.linkWithRedirect(this._delegate, provider, CompatPopupRedirectResolver);
536
+ }
537
+ reauthenticateAndRetrieveDataWithCredential(credential) {
538
+ return this.reauthenticateWithCredential(credential);
539
+ }
540
+ async reauthenticateWithCredential(credential) {
541
+ return convertCredential(this.auth, exp.reauthenticateWithCredential(this._delegate, credential));
542
+ }
543
+ reauthenticateWithPhoneNumber(phoneNumber, applicationVerifier) {
544
+ return convertConfirmationResult(this.auth, exp.reauthenticateWithPhoneNumber(this._delegate, phoneNumber, applicationVerifier));
545
+ }
546
+ reauthenticateWithPopup(provider) {
547
+ return convertCredential(this.auth, exp.reauthenticateWithPopup(this._delegate, provider, CompatPopupRedirectResolver));
548
+ }
549
+ async reauthenticateWithRedirect(provider) {
550
+ await _savePersistenceForRedirect(exp._castAuth(this.auth));
551
+ return exp.reauthenticateWithRedirect(this._delegate, provider, CompatPopupRedirectResolver);
552
+ }
553
+ sendEmailVerification(actionCodeSettings) {
554
+ return exp.sendEmailVerification(this._delegate, actionCodeSettings);
555
+ }
556
+ async unlink(providerId) {
557
+ await exp.unlink(this._delegate, providerId);
558
+ return this;
559
+ }
560
+ updateEmail(newEmail) {
561
+ return exp.updateEmail(this._delegate, newEmail);
562
+ }
563
+ updatePassword(newPassword) {
564
+ return exp.updatePassword(this._delegate, newPassword);
565
+ }
566
+ updatePhoneNumber(phoneCredential) {
567
+ return exp.updatePhoneNumber(this._delegate, phoneCredential);
568
+ }
569
+ updateProfile(profile) {
570
+ return exp.updateProfile(this._delegate, profile);
571
+ }
572
+ verifyBeforeUpdateEmail(newEmail, actionCodeSettings) {
573
+ return exp.verifyBeforeUpdateEmail(this._delegate, newEmail, actionCodeSettings);
574
+ }
575
+ get emailVerified() {
576
+ return this._delegate.emailVerified;
577
+ }
578
+ get isAnonymous() {
579
+ return this._delegate.isAnonymous;
580
+ }
581
+ get metadata() {
582
+ return this._delegate.metadata;
583
+ }
584
+ get phoneNumber() {
585
+ return this._delegate.phoneNumber;
586
+ }
587
+ get providerData() {
588
+ return this._delegate.providerData;
589
+ }
590
+ get refreshToken() {
591
+ return this._delegate.refreshToken;
592
+ }
593
+ get tenantId() {
594
+ return this._delegate.tenantId;
595
+ }
596
+ get displayName() {
597
+ return this._delegate.displayName;
598
+ }
599
+ get email() {
600
+ return this._delegate.email;
601
+ }
602
+ get photoURL() {
603
+ return this._delegate.photoURL;
604
+ }
605
+ get providerId() {
606
+ return this._delegate.providerId;
607
+ }
608
+ get uid() {
609
+ return this._delegate.uid;
610
+ }
611
+ get auth() {
612
+ return this._delegate.auth;
613
+ }
614
+ }
615
+ // Maintain a map so that there's always a 1:1 mapping between new User and
616
+ // legacy compat users
617
617
  User.USER_MAP = new WeakMap();
618
618
 
619
- /**
620
- * @license
621
- * Copyright 2020 Google LLC
622
- *
623
- * Licensed under the Apache License, Version 2.0 (the "License");
624
- * you may not use this file except in compliance with the License.
625
- * You may obtain a copy of the License at
626
- *
627
- * http://www.apache.org/licenses/LICENSE-2.0
628
- *
629
- * Unless required by applicable law or agreed to in writing, software
630
- * distributed under the License is distributed on an "AS IS" BASIS,
631
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
632
- * See the License for the specific language governing permissions and
633
- * limitations under the License.
634
- */
635
- const _assert$1 = exp._assert;
636
- class Auth {
637
- constructor(app, provider) {
638
- this.app = app;
639
- if (provider.isInitialized()) {
640
- this._delegate = provider.getImmediate();
641
- this.linkUnderlyingAuth();
642
- return;
643
- }
644
- const { apiKey } = app.options;
645
- // TODO: platform needs to be determined using heuristics
646
- _assert$1(apiKey, "invalid-api-key" /* exp.AuthErrorCode.INVALID_API_KEY */, {
647
- appName: app.name
648
- });
649
- // TODO: platform needs to be determined using heuristics
650
- _assert$1(apiKey, "invalid-api-key" /* exp.AuthErrorCode.INVALID_API_KEY */, {
651
- appName: app.name
652
- });
653
- // Only use a popup/redirect resolver in browser environments
654
- const resolver = typeof window !== 'undefined' ? CompatPopupRedirectResolver : undefined;
655
- this._delegate = provider.initialize({
656
- options: {
657
- persistence: buildPersistenceHierarchy(apiKey, app.name),
658
- popupRedirectResolver: resolver
659
- }
660
- });
661
- this._delegate._updateErrorMap(exp.debugErrorMap);
662
- this.linkUnderlyingAuth();
663
- }
664
- get emulatorConfig() {
665
- return this._delegate.emulatorConfig;
666
- }
667
- get currentUser() {
668
- if (!this._delegate.currentUser) {
669
- return null;
670
- }
671
- return User.getOrCreate(this._delegate.currentUser);
672
- }
673
- get languageCode() {
674
- return this._delegate.languageCode;
675
- }
676
- set languageCode(languageCode) {
677
- this._delegate.languageCode = languageCode;
678
- }
679
- get settings() {
680
- return this._delegate.settings;
681
- }
682
- get tenantId() {
683
- return this._delegate.tenantId;
684
- }
685
- set tenantId(tid) {
686
- this._delegate.tenantId = tid;
687
- }
688
- useDeviceLanguage() {
689
- this._delegate.useDeviceLanguage();
690
- }
691
- signOut() {
692
- return this._delegate.signOut();
693
- }
694
- useEmulator(url, options) {
695
- exp.connectAuthEmulator(this._delegate, url, options);
696
- }
697
- applyActionCode(code) {
698
- return exp.applyActionCode(this._delegate, code);
699
- }
700
- checkActionCode(code) {
701
- return exp.checkActionCode(this._delegate, code);
702
- }
703
- confirmPasswordReset(code, newPassword) {
704
- return exp.confirmPasswordReset(this._delegate, code, newPassword);
705
- }
706
- async createUserWithEmailAndPassword(email, password) {
707
- return convertCredential(this._delegate, exp.createUserWithEmailAndPassword(this._delegate, email, password));
708
- }
709
- fetchProvidersForEmail(email) {
710
- return this.fetchSignInMethodsForEmail(email);
711
- }
712
- fetchSignInMethodsForEmail(email) {
713
- return exp.fetchSignInMethodsForEmail(this._delegate, email);
714
- }
715
- isSignInWithEmailLink(emailLink) {
716
- return exp.isSignInWithEmailLink(this._delegate, emailLink);
717
- }
718
- async getRedirectResult() {
719
- _assert$1(_isPopupRedirectSupported(), this._delegate, "operation-not-supported-in-this-environment" /* exp.AuthErrorCode.OPERATION_NOT_SUPPORTED */);
720
- const credential = await exp.getRedirectResult(this._delegate, CompatPopupRedirectResolver);
721
- if (!credential) {
722
- return {
723
- credential: null,
724
- user: null
725
- };
726
- }
727
- return convertCredential(this._delegate, Promise.resolve(credential));
728
- }
729
- // This function should only be called by frameworks (e.g. FirebaseUI-web) to log their usage.
730
- // It is not intended for direct use by developer apps. NO jsdoc here to intentionally leave it
731
- // out of autogenerated documentation pages to reduce accidental misuse.
732
- addFrameworkForLogging(framework) {
733
- exp.addFrameworkForLogging(this._delegate, framework);
734
- }
735
- onAuthStateChanged(nextOrObserver, errorFn, completed) {
736
- const { next, error, complete } = wrapObservers(nextOrObserver, errorFn, completed);
737
- return this._delegate.onAuthStateChanged(next, error, complete);
738
- }
739
- onIdTokenChanged(nextOrObserver, errorFn, completed) {
740
- const { next, error, complete } = wrapObservers(nextOrObserver, errorFn, completed);
741
- return this._delegate.onIdTokenChanged(next, error, complete);
742
- }
743
- sendSignInLinkToEmail(email, actionCodeSettings) {
744
- return exp.sendSignInLinkToEmail(this._delegate, email, actionCodeSettings);
745
- }
746
- sendPasswordResetEmail(email, actionCodeSettings) {
747
- return exp.sendPasswordResetEmail(this._delegate, email, actionCodeSettings || undefined);
748
- }
749
- async setPersistence(persistence) {
750
- _validatePersistenceArgument(this._delegate, persistence);
751
- let converted;
752
- switch (persistence) {
753
- case Persistence.SESSION:
754
- converted = exp.browserSessionPersistence;
755
- break;
756
- case Persistence.LOCAL:
757
- // Not using isIndexedDBAvailable() since it only checks if indexedDB is defined.
758
- const isIndexedDBFullySupported = await exp
759
- ._getInstance(exp.indexedDBLocalPersistence)
760
- ._isAvailable();
761
- converted = isIndexedDBFullySupported
762
- ? exp.indexedDBLocalPersistence
763
- : exp.browserLocalPersistence;
764
- break;
765
- case Persistence.NONE:
766
- converted = exp.inMemoryPersistence;
767
- break;
768
- default:
769
- return exp._fail("argument-error" /* exp.AuthErrorCode.ARGUMENT_ERROR */, {
770
- appName: this._delegate.name
771
- });
772
- }
773
- return this._delegate.setPersistence(converted);
774
- }
775
- signInAndRetrieveDataWithCredential(credential) {
776
- return this.signInWithCredential(credential);
777
- }
778
- signInAnonymously() {
779
- return convertCredential(this._delegate, exp.signInAnonymously(this._delegate));
780
- }
781
- signInWithCredential(credential) {
782
- return convertCredential(this._delegate, exp.signInWithCredential(this._delegate, credential));
783
- }
784
- signInWithCustomToken(token) {
785
- return convertCredential(this._delegate, exp.signInWithCustomToken(this._delegate, token));
786
- }
787
- signInWithEmailAndPassword(email, password) {
788
- return convertCredential(this._delegate, exp.signInWithEmailAndPassword(this._delegate, email, password));
789
- }
790
- signInWithEmailLink(email, emailLink) {
791
- return convertCredential(this._delegate, exp.signInWithEmailLink(this._delegate, email, emailLink));
792
- }
793
- signInWithPhoneNumber(phoneNumber, applicationVerifier) {
794
- return convertConfirmationResult(this._delegate, exp.signInWithPhoneNumber(this._delegate, phoneNumber, applicationVerifier));
795
- }
796
- async signInWithPopup(provider) {
797
- _assert$1(_isPopupRedirectSupported(), this._delegate, "operation-not-supported-in-this-environment" /* exp.AuthErrorCode.OPERATION_NOT_SUPPORTED */);
798
- return convertCredential(this._delegate, exp.signInWithPopup(this._delegate, provider, CompatPopupRedirectResolver));
799
- }
800
- async signInWithRedirect(provider) {
801
- _assert$1(_isPopupRedirectSupported(), this._delegate, "operation-not-supported-in-this-environment" /* exp.AuthErrorCode.OPERATION_NOT_SUPPORTED */);
802
- await _savePersistenceForRedirect(this._delegate);
803
- return exp.signInWithRedirect(this._delegate, provider, CompatPopupRedirectResolver);
804
- }
805
- updateCurrentUser(user) {
806
- // remove ts-ignore once overloads are defined for exp functions to accept compat objects
807
- // @ts-ignore
808
- return this._delegate.updateCurrentUser(user);
809
- }
810
- verifyPasswordResetCode(code) {
811
- return exp.verifyPasswordResetCode(this._delegate, code);
812
- }
813
- unwrap() {
814
- return this._delegate;
815
- }
816
- _delete() {
817
- return this._delegate._delete();
818
- }
819
- linkUnderlyingAuth() {
820
- this._delegate.wrapped = () => this;
821
- }
822
- }
823
- Auth.Persistence = Persistence;
824
- function wrapObservers(nextOrObserver, error, complete) {
825
- let next = nextOrObserver;
826
- if (typeof nextOrObserver !== 'function') {
827
- ({ next, error, complete } = nextOrObserver);
828
- }
829
- // We know 'next' is now a function
830
- const oldNext = next;
831
- const newNext = (user) => oldNext(user && User.getOrCreate(user));
832
- return {
833
- next: newNext,
834
- error: error,
835
- complete
836
- };
837
- }
838
- function buildPersistenceHierarchy(apiKey, appName) {
839
- // Note this is slightly different behavior: in this case, the stored
840
- // persistence is checked *first* rather than last. This is because we want
841
- // to prefer stored persistence type in the hierarchy. This is an empty
842
- // array if window is not available or there is no pending redirect
843
- const persistences = _getPersistencesFromRedirect(apiKey, appName);
844
- // If "self" is available, add indexedDB
845
- if (typeof self !== 'undefined' &&
846
- !persistences.includes(exp.indexedDBLocalPersistence)) {
847
- persistences.push(exp.indexedDBLocalPersistence);
848
- }
849
- // If "window" is available, add HTML Storage persistences
850
- if (typeof window !== 'undefined') {
851
- for (const persistence of [
852
- exp.browserLocalPersistence,
853
- exp.browserSessionPersistence
854
- ]) {
855
- if (!persistences.includes(persistence)) {
856
- persistences.push(persistence);
857
- }
858
- }
859
- }
860
- // Add in-memory as a final fallback
861
- if (!persistences.includes(exp.inMemoryPersistence)) {
862
- persistences.push(exp.inMemoryPersistence);
863
- }
864
- return persistences;
619
+ /**
620
+ * @license
621
+ * Copyright 2020 Google LLC
622
+ *
623
+ * Licensed under the Apache License, Version 2.0 (the "License");
624
+ * you may not use this file except in compliance with the License.
625
+ * You may obtain a copy of the License at
626
+ *
627
+ * http://www.apache.org/licenses/LICENSE-2.0
628
+ *
629
+ * Unless required by applicable law or agreed to in writing, software
630
+ * distributed under the License is distributed on an "AS IS" BASIS,
631
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
632
+ * See the License for the specific language governing permissions and
633
+ * limitations under the License.
634
+ */
635
+ const _assert$1 = exp._assert;
636
+ class Auth {
637
+ constructor(app, provider) {
638
+ this.app = app;
639
+ if (provider.isInitialized()) {
640
+ this._delegate = provider.getImmediate();
641
+ this.linkUnderlyingAuth();
642
+ return;
643
+ }
644
+ const { apiKey } = app.options;
645
+ // TODO: platform needs to be determined using heuristics
646
+ _assert$1(apiKey, "invalid-api-key" /* exp.AuthErrorCode.INVALID_API_KEY */, {
647
+ appName: app.name
648
+ });
649
+ // TODO: platform needs to be determined using heuristics
650
+ _assert$1(apiKey, "invalid-api-key" /* exp.AuthErrorCode.INVALID_API_KEY */, {
651
+ appName: app.name
652
+ });
653
+ // Only use a popup/redirect resolver in browser environments
654
+ const resolver = typeof window !== 'undefined' ? CompatPopupRedirectResolver : undefined;
655
+ this._delegate = provider.initialize({
656
+ options: {
657
+ persistence: buildPersistenceHierarchy(apiKey, app.name),
658
+ popupRedirectResolver: resolver
659
+ }
660
+ });
661
+ this._delegate._updateErrorMap(exp.debugErrorMap);
662
+ this.linkUnderlyingAuth();
663
+ }
664
+ get emulatorConfig() {
665
+ return this._delegate.emulatorConfig;
666
+ }
667
+ get currentUser() {
668
+ if (!this._delegate.currentUser) {
669
+ return null;
670
+ }
671
+ return User.getOrCreate(this._delegate.currentUser);
672
+ }
673
+ get languageCode() {
674
+ return this._delegate.languageCode;
675
+ }
676
+ set languageCode(languageCode) {
677
+ this._delegate.languageCode = languageCode;
678
+ }
679
+ get settings() {
680
+ return this._delegate.settings;
681
+ }
682
+ get tenantId() {
683
+ return this._delegate.tenantId;
684
+ }
685
+ set tenantId(tid) {
686
+ this._delegate.tenantId = tid;
687
+ }
688
+ useDeviceLanguage() {
689
+ this._delegate.useDeviceLanguage();
690
+ }
691
+ signOut() {
692
+ return this._delegate.signOut();
693
+ }
694
+ useEmulator(url, options) {
695
+ exp.connectAuthEmulator(this._delegate, url, options);
696
+ }
697
+ applyActionCode(code) {
698
+ return exp.applyActionCode(this._delegate, code);
699
+ }
700
+ checkActionCode(code) {
701
+ return exp.checkActionCode(this._delegate, code);
702
+ }
703
+ confirmPasswordReset(code, newPassword) {
704
+ return exp.confirmPasswordReset(this._delegate, code, newPassword);
705
+ }
706
+ async createUserWithEmailAndPassword(email, password) {
707
+ return convertCredential(this._delegate, exp.createUserWithEmailAndPassword(this._delegate, email, password));
708
+ }
709
+ fetchProvidersForEmail(email) {
710
+ return this.fetchSignInMethodsForEmail(email);
711
+ }
712
+ fetchSignInMethodsForEmail(email) {
713
+ return exp.fetchSignInMethodsForEmail(this._delegate, email);
714
+ }
715
+ isSignInWithEmailLink(emailLink) {
716
+ return exp.isSignInWithEmailLink(this._delegate, emailLink);
717
+ }
718
+ async getRedirectResult() {
719
+ _assert$1(_isPopupRedirectSupported(), this._delegate, "operation-not-supported-in-this-environment" /* exp.AuthErrorCode.OPERATION_NOT_SUPPORTED */);
720
+ const credential = await exp.getRedirectResult(this._delegate, CompatPopupRedirectResolver);
721
+ if (!credential) {
722
+ return {
723
+ credential: null,
724
+ user: null
725
+ };
726
+ }
727
+ return convertCredential(this._delegate, Promise.resolve(credential));
728
+ }
729
+ // This function should only be called by frameworks (e.g. FirebaseUI-web) to log their usage.
730
+ // It is not intended for direct use by developer apps. NO jsdoc here to intentionally leave it
731
+ // out of autogenerated documentation pages to reduce accidental misuse.
732
+ addFrameworkForLogging(framework) {
733
+ exp.addFrameworkForLogging(this._delegate, framework);
734
+ }
735
+ onAuthStateChanged(nextOrObserver, errorFn, completed) {
736
+ const { next, error, complete } = wrapObservers(nextOrObserver, errorFn, completed);
737
+ return this._delegate.onAuthStateChanged(next, error, complete);
738
+ }
739
+ onIdTokenChanged(nextOrObserver, errorFn, completed) {
740
+ const { next, error, complete } = wrapObservers(nextOrObserver, errorFn, completed);
741
+ return this._delegate.onIdTokenChanged(next, error, complete);
742
+ }
743
+ sendSignInLinkToEmail(email, actionCodeSettings) {
744
+ return exp.sendSignInLinkToEmail(this._delegate, email, actionCodeSettings);
745
+ }
746
+ sendPasswordResetEmail(email, actionCodeSettings) {
747
+ return exp.sendPasswordResetEmail(this._delegate, email, actionCodeSettings || undefined);
748
+ }
749
+ async setPersistence(persistence) {
750
+ _validatePersistenceArgument(this._delegate, persistence);
751
+ let converted;
752
+ switch (persistence) {
753
+ case Persistence.SESSION:
754
+ converted = exp.browserSessionPersistence;
755
+ break;
756
+ case Persistence.LOCAL:
757
+ // Not using isIndexedDBAvailable() since it only checks if indexedDB is defined.
758
+ const isIndexedDBFullySupported = await exp
759
+ ._getInstance(exp.indexedDBLocalPersistence)
760
+ ._isAvailable();
761
+ converted = isIndexedDBFullySupported
762
+ ? exp.indexedDBLocalPersistence
763
+ : exp.browserLocalPersistence;
764
+ break;
765
+ case Persistence.NONE:
766
+ converted = exp.inMemoryPersistence;
767
+ break;
768
+ default:
769
+ return exp._fail("argument-error" /* exp.AuthErrorCode.ARGUMENT_ERROR */, {
770
+ appName: this._delegate.name
771
+ });
772
+ }
773
+ return this._delegate.setPersistence(converted);
774
+ }
775
+ signInAndRetrieveDataWithCredential(credential) {
776
+ return this.signInWithCredential(credential);
777
+ }
778
+ signInAnonymously() {
779
+ return convertCredential(this._delegate, exp.signInAnonymously(this._delegate));
780
+ }
781
+ signInWithCredential(credential) {
782
+ return convertCredential(this._delegate, exp.signInWithCredential(this._delegate, credential));
783
+ }
784
+ signInWithCustomToken(token) {
785
+ return convertCredential(this._delegate, exp.signInWithCustomToken(this._delegate, token));
786
+ }
787
+ signInWithEmailAndPassword(email, password) {
788
+ return convertCredential(this._delegate, exp.signInWithEmailAndPassword(this._delegate, email, password));
789
+ }
790
+ signInWithEmailLink(email, emailLink) {
791
+ return convertCredential(this._delegate, exp.signInWithEmailLink(this._delegate, email, emailLink));
792
+ }
793
+ signInWithPhoneNumber(phoneNumber, applicationVerifier) {
794
+ return convertConfirmationResult(this._delegate, exp.signInWithPhoneNumber(this._delegate, phoneNumber, applicationVerifier));
795
+ }
796
+ async signInWithPopup(provider) {
797
+ _assert$1(_isPopupRedirectSupported(), this._delegate, "operation-not-supported-in-this-environment" /* exp.AuthErrorCode.OPERATION_NOT_SUPPORTED */);
798
+ return convertCredential(this._delegate, exp.signInWithPopup(this._delegate, provider, CompatPopupRedirectResolver));
799
+ }
800
+ async signInWithRedirect(provider) {
801
+ _assert$1(_isPopupRedirectSupported(), this._delegate, "operation-not-supported-in-this-environment" /* exp.AuthErrorCode.OPERATION_NOT_SUPPORTED */);
802
+ await _savePersistenceForRedirect(this._delegate);
803
+ return exp.signInWithRedirect(this._delegate, provider, CompatPopupRedirectResolver);
804
+ }
805
+ updateCurrentUser(user) {
806
+ // remove ts-ignore once overloads are defined for exp functions to accept compat objects
807
+ // @ts-ignore
808
+ return this._delegate.updateCurrentUser(user);
809
+ }
810
+ verifyPasswordResetCode(code) {
811
+ return exp.verifyPasswordResetCode(this._delegate, code);
812
+ }
813
+ unwrap() {
814
+ return this._delegate;
815
+ }
816
+ _delete() {
817
+ return this._delegate._delete();
818
+ }
819
+ linkUnderlyingAuth() {
820
+ this._delegate.wrapped = () => this;
821
+ }
822
+ }
823
+ Auth.Persistence = Persistence;
824
+ function wrapObservers(nextOrObserver, error, complete) {
825
+ let next = nextOrObserver;
826
+ if (typeof nextOrObserver !== 'function') {
827
+ ({ next, error, complete } = nextOrObserver);
828
+ }
829
+ // We know 'next' is now a function
830
+ const oldNext = next;
831
+ const newNext = (user) => oldNext(user && User.getOrCreate(user));
832
+ return {
833
+ next: newNext,
834
+ error: error,
835
+ complete
836
+ };
837
+ }
838
+ function buildPersistenceHierarchy(apiKey, appName) {
839
+ // Note this is slightly different behavior: in this case, the stored
840
+ // persistence is checked *first* rather than last. This is because we want
841
+ // to prefer stored persistence type in the hierarchy. This is an empty
842
+ // array if window is not available or there is no pending redirect
843
+ const persistences = _getPersistencesFromRedirect(apiKey, appName);
844
+ // If "self" is available, add indexedDB
845
+ if (typeof self !== 'undefined' &&
846
+ !persistences.includes(exp.indexedDBLocalPersistence)) {
847
+ persistences.push(exp.indexedDBLocalPersistence);
848
+ }
849
+ // If "window" is available, add HTML Storage persistences
850
+ if (typeof window !== 'undefined') {
851
+ for (const persistence of [
852
+ exp.browserLocalPersistence,
853
+ exp.browserSessionPersistence
854
+ ]) {
855
+ if (!persistences.includes(persistence)) {
856
+ persistences.push(persistence);
857
+ }
858
+ }
859
+ }
860
+ // Add in-memory as a final fallback
861
+ if (!persistences.includes(exp.inMemoryPersistence)) {
862
+ persistences.push(exp.inMemoryPersistence);
863
+ }
864
+ return persistences;
865
865
  }
866
866
 
867
- /**
868
- * @license
869
- * Copyright 2020 Google LLC
870
- *
871
- * Licensed under the Apache License, Version 2.0 (the "License");
872
- * you may not use this file except in compliance with the License.
873
- * You may obtain a copy of the License at
874
- *
875
- * http://www.apache.org/licenses/LICENSE-2.0
876
- *
877
- * Unless required by applicable law or agreed to in writing, software
878
- * distributed under the License is distributed on an "AS IS" BASIS,
879
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
880
- * See the License for the specific language governing permissions and
881
- * limitations under the License.
882
- */
883
- class PhoneAuthProvider {
884
- constructor() {
885
- this.providerId = 'phone';
886
- // TODO: remove ts-ignore when moving types from auth-types to auth-compat
887
- // @ts-ignore
888
- this._delegate = new exp.PhoneAuthProvider(unwrap(firebase.auth()));
889
- }
890
- static credential(verificationId, verificationCode) {
891
- return exp.PhoneAuthProvider.credential(verificationId, verificationCode);
892
- }
893
- verifyPhoneNumber(phoneInfoOptions, applicationVerifier) {
894
- return this._delegate.verifyPhoneNumber(
895
- // The implementation matches but the types are subtly incompatible
896
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
897
- phoneInfoOptions, applicationVerifier);
898
- }
899
- unwrap() {
900
- return this._delegate;
901
- }
902
- }
903
- PhoneAuthProvider.PHONE_SIGN_IN_METHOD = exp.PhoneAuthProvider.PHONE_SIGN_IN_METHOD;
867
+ /**
868
+ * @license
869
+ * Copyright 2020 Google LLC
870
+ *
871
+ * Licensed under the Apache License, Version 2.0 (the "License");
872
+ * you may not use this file except in compliance with the License.
873
+ * You may obtain a copy of the License at
874
+ *
875
+ * http://www.apache.org/licenses/LICENSE-2.0
876
+ *
877
+ * Unless required by applicable law or agreed to in writing, software
878
+ * distributed under the License is distributed on an "AS IS" BASIS,
879
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
880
+ * See the License for the specific language governing permissions and
881
+ * limitations under the License.
882
+ */
883
+ class PhoneAuthProvider {
884
+ static credential(verificationId, verificationCode) {
885
+ return exp.PhoneAuthProvider.credential(verificationId, verificationCode);
886
+ }
887
+ constructor() {
888
+ this.providerId = 'phone';
889
+ // TODO: remove ts-ignore when moving types from auth-types to auth-compat
890
+ // @ts-ignore
891
+ this._delegate = new exp.PhoneAuthProvider(unwrap(firebase.auth()));
892
+ }
893
+ verifyPhoneNumber(phoneInfoOptions, applicationVerifier) {
894
+ return this._delegate.verifyPhoneNumber(
895
+ // The implementation matches but the types are subtly incompatible
896
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
897
+ phoneInfoOptions, applicationVerifier);
898
+ }
899
+ unwrap() {
900
+ return this._delegate;
901
+ }
902
+ }
903
+ PhoneAuthProvider.PHONE_SIGN_IN_METHOD = exp.PhoneAuthProvider.PHONE_SIGN_IN_METHOD;
904
904
  PhoneAuthProvider.PROVIDER_ID = exp.PhoneAuthProvider.PROVIDER_ID;
905
905
 
906
- /**
907
- * @license
908
- * Copyright 2020 Google LLC
909
- *
910
- * Licensed under the Apache License, Version 2.0 (the "License");
911
- * you may not use this file except in compliance with the License.
912
- * You may obtain a copy of the License at
913
- *
914
- * http://www.apache.org/licenses/LICENSE-2.0
915
- *
916
- * Unless required by applicable law or agreed to in writing, software
917
- * distributed under the License is distributed on an "AS IS" BASIS,
918
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
919
- * See the License for the specific language governing permissions and
920
- * limitations under the License.
921
- */
922
- const _assert = exp._assert;
923
- class RecaptchaVerifier {
924
- constructor(container, parameters, app = firebase.app()) {
925
- var _a;
926
- // API key is required for web client RPC calls.
927
- _assert((_a = app.options) === null || _a === void 0 ? void 0 : _a.apiKey, "invalid-api-key" /* exp.AuthErrorCode.INVALID_API_KEY */, {
928
- appName: app.name
929
- });
930
- this._delegate = new exp.RecaptchaVerifier(
931
- // TODO: remove ts-ignore when moving types from auth-types to auth-compat
932
- // @ts-ignore
933
- app.auth(), container,
934
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
935
- parameters);
936
- this.type = this._delegate.type;
937
- }
938
- clear() {
939
- this._delegate.clear();
940
- }
941
- render() {
942
- return this._delegate.render();
943
- }
944
- verify() {
945
- return this._delegate.verify();
946
- }
906
+ /**
907
+ * @license
908
+ * Copyright 2020 Google LLC
909
+ *
910
+ * Licensed under the Apache License, Version 2.0 (the "License");
911
+ * you may not use this file except in compliance with the License.
912
+ * You may obtain a copy of the License at
913
+ *
914
+ * http://www.apache.org/licenses/LICENSE-2.0
915
+ *
916
+ * Unless required by applicable law or agreed to in writing, software
917
+ * distributed under the License is distributed on an "AS IS" BASIS,
918
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
919
+ * See the License for the specific language governing permissions and
920
+ * limitations under the License.
921
+ */
922
+ const _assert = exp._assert;
923
+ class RecaptchaVerifier {
924
+ constructor(container, parameters, app = firebase.app()) {
925
+ var _a;
926
+ // API key is required for web client RPC calls.
927
+ _assert((_a = app.options) === null || _a === void 0 ? void 0 : _a.apiKey, "invalid-api-key" /* exp.AuthErrorCode.INVALID_API_KEY */, {
928
+ appName: app.name
929
+ });
930
+ this._delegate = new exp.RecaptchaVerifier(
931
+ // TODO: remove ts-ignore when moving types from auth-types to auth-compat
932
+ // @ts-ignore
933
+ app.auth(), container,
934
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
935
+ parameters);
936
+ this.type = this._delegate.type;
937
+ }
938
+ clear() {
939
+ this._delegate.clear();
940
+ }
941
+ render() {
942
+ return this._delegate.render();
943
+ }
944
+ verify() {
945
+ return this._delegate.verify();
946
+ }
947
947
  }
948
948
 
949
- /**
950
- * @license
951
- * Copyright 2020 Google LLC
952
- *
953
- * Licensed under the Apache License, Version 2.0 (the "License");
954
- * you may not use this file except in compliance with the License.
955
- * You may obtain a copy of the License at
956
- *
957
- * http://www.apache.org/licenses/LICENSE-2.0
958
- *
959
- * Unless required by applicable law or agreed to in writing, software
960
- * distributed under the License is distributed on an "AS IS" BASIS,
961
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
962
- * See the License for the specific language governing permissions and
963
- * limitations under the License.
964
- */
965
- const AUTH_TYPE = 'auth-compat';
966
- // Create auth components to register with firebase.
967
- // Provides Auth public APIs.
968
- function registerAuthCompat(instance) {
969
- instance.INTERNAL.registerComponent(new Component(AUTH_TYPE, container => {
970
- // getImmediate for FirebaseApp will always succeed
971
- const app = container.getProvider('app-compat').getImmediate();
972
- const authProvider = container.getProvider('auth');
973
- return new Auth(app, authProvider);
974
- }, "PUBLIC" /* ComponentType.PUBLIC */)
975
- .setServiceProps({
976
- ActionCodeInfo: {
977
- Operation: {
978
- EMAIL_SIGNIN: exp.ActionCodeOperation.EMAIL_SIGNIN,
979
- PASSWORD_RESET: exp.ActionCodeOperation.PASSWORD_RESET,
980
- RECOVER_EMAIL: exp.ActionCodeOperation.RECOVER_EMAIL,
981
- REVERT_SECOND_FACTOR_ADDITION: exp.ActionCodeOperation.REVERT_SECOND_FACTOR_ADDITION,
982
- VERIFY_AND_CHANGE_EMAIL: exp.ActionCodeOperation.VERIFY_AND_CHANGE_EMAIL,
983
- VERIFY_EMAIL: exp.ActionCodeOperation.VERIFY_EMAIL
984
- }
985
- },
986
- EmailAuthProvider: exp.EmailAuthProvider,
987
- FacebookAuthProvider: exp.FacebookAuthProvider,
988
- GithubAuthProvider: exp.GithubAuthProvider,
989
- GoogleAuthProvider: exp.GoogleAuthProvider,
990
- OAuthProvider: exp.OAuthProvider,
991
- SAMLAuthProvider: exp.SAMLAuthProvider,
992
- PhoneAuthProvider: PhoneAuthProvider,
993
- PhoneMultiFactorGenerator: exp.PhoneMultiFactorGenerator,
994
- RecaptchaVerifier: RecaptchaVerifier,
995
- TwitterAuthProvider: exp.TwitterAuthProvider,
996
- Auth,
997
- AuthCredential: exp.AuthCredential,
998
- Error: FirebaseError
999
- })
1000
- .setInstantiationMode("LAZY" /* InstantiationMode.LAZY */)
1001
- .setMultipleInstances(false));
1002
- instance.registerVersion(name, version);
1003
- }
949
+ /**
950
+ * @license
951
+ * Copyright 2020 Google LLC
952
+ *
953
+ * Licensed under the Apache License, Version 2.0 (the "License");
954
+ * you may not use this file except in compliance with the License.
955
+ * You may obtain a copy of the License at
956
+ *
957
+ * http://www.apache.org/licenses/LICENSE-2.0
958
+ *
959
+ * Unless required by applicable law or agreed to in writing, software
960
+ * distributed under the License is distributed on an "AS IS" BASIS,
961
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
962
+ * See the License for the specific language governing permissions and
963
+ * limitations under the License.
964
+ */
965
+ const AUTH_TYPE = 'auth-compat';
966
+ // Create auth components to register with firebase.
967
+ // Provides Auth public APIs.
968
+ function registerAuthCompat(instance) {
969
+ instance.INTERNAL.registerComponent(new Component(AUTH_TYPE, container => {
970
+ // getImmediate for FirebaseApp will always succeed
971
+ const app = container.getProvider('app-compat').getImmediate();
972
+ const authProvider = container.getProvider('auth');
973
+ return new Auth(app, authProvider);
974
+ }, "PUBLIC" /* ComponentType.PUBLIC */)
975
+ .setServiceProps({
976
+ ActionCodeInfo: {
977
+ Operation: {
978
+ EMAIL_SIGNIN: exp.ActionCodeOperation.EMAIL_SIGNIN,
979
+ PASSWORD_RESET: exp.ActionCodeOperation.PASSWORD_RESET,
980
+ RECOVER_EMAIL: exp.ActionCodeOperation.RECOVER_EMAIL,
981
+ REVERT_SECOND_FACTOR_ADDITION: exp.ActionCodeOperation.REVERT_SECOND_FACTOR_ADDITION,
982
+ VERIFY_AND_CHANGE_EMAIL: exp.ActionCodeOperation.VERIFY_AND_CHANGE_EMAIL,
983
+ VERIFY_EMAIL: exp.ActionCodeOperation.VERIFY_EMAIL
984
+ }
985
+ },
986
+ EmailAuthProvider: exp.EmailAuthProvider,
987
+ FacebookAuthProvider: exp.FacebookAuthProvider,
988
+ GithubAuthProvider: exp.GithubAuthProvider,
989
+ GoogleAuthProvider: exp.GoogleAuthProvider,
990
+ OAuthProvider: exp.OAuthProvider,
991
+ SAMLAuthProvider: exp.SAMLAuthProvider,
992
+ PhoneAuthProvider: PhoneAuthProvider,
993
+ PhoneMultiFactorGenerator: exp.PhoneMultiFactorGenerator,
994
+ RecaptchaVerifier: RecaptchaVerifier,
995
+ TwitterAuthProvider: exp.TwitterAuthProvider,
996
+ Auth,
997
+ AuthCredential: exp.AuthCredential,
998
+ Error: FirebaseError
999
+ })
1000
+ .setInstantiationMode("LAZY" /* InstantiationMode.LAZY */)
1001
+ .setMultipleInstances(false));
1002
+ instance.registerVersion(name, version);
1003
+ }
1004
1004
  registerAuthCompat(firebase);
1005
1005
 
1006
- /**
1007
- * @license
1008
- * Copyright 2017 Google LLC
1009
- *
1010
- * Licensed under the Apache License, Version 2.0 (the "License");
1011
- * you may not use this file except in compliance with the License.
1012
- * You may obtain a copy of the License at
1013
- *
1014
- * http://www.apache.org/licenses/LICENSE-2.0
1015
- *
1016
- * Unless required by applicable law or agreed to in writing, software
1017
- * distributed under the License is distributed on an "AS IS" BASIS,
1018
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1019
- * See the License for the specific language governing permissions and
1020
- * limitations under the License.
1021
- */
1006
+ /**
1007
+ * @license
1008
+ * Copyright 2017 Google LLC
1009
+ *
1010
+ * Licensed under the Apache License, Version 2.0 (the "License");
1011
+ * you may not use this file except in compliance with the License.
1012
+ * You may obtain a copy of the License at
1013
+ *
1014
+ * http://www.apache.org/licenses/LICENSE-2.0
1015
+ *
1016
+ * Unless required by applicable law or agreed to in writing, software
1017
+ * distributed under the License is distributed on an "AS IS" BASIS,
1018
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1019
+ * See the License for the specific language governing permissions and
1020
+ * limitations under the License.
1021
+ */
1022
1022
  FetchProvider.initialize(fetch, Headers, Response);
1023
1023
  //# sourceMappingURL=index.node.esm.js.map