@depup/firebase__auth-compat 0.6.3-depup.0

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