index.cjs.js 41 KB

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