@firebase/auth-compat 0.1.6 → 0.2.0-canary.0b3ca78eb

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