No Description
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.esm.js 50KB

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