Ei kuvausta
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.node.cjs.js 53KB

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