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