@firebase/auth 1.13.3 → 1.13.4-20260728185501
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser-cjs/{index-80e3689c.js → index-TiyvRZm6.js} +119 -26
- package/dist/browser-cjs/{index-80e3689c.js.map → index-TiyvRZm6.js.map} +1 -1
- package/dist/browser-cjs/index.js +1 -1
- package/dist/browser-cjs/internal.js +1 -1
- package/dist/browser-cjs/internal.js.map +1 -1
- package/dist/cordova/index.js +9 -3
- package/dist/cordova/index.js.map +1 -1
- package/dist/cordova/internal.js +3 -3
- package/dist/cordova/internal.js.map +1 -1
- package/dist/cordova/{popup_redirect-167cbb8f.js → popup_redirect-Be0Melsy.js} +148 -55
- package/dist/cordova/popup_redirect-Be0Melsy.js.map +1 -0
- package/dist/esm/{index-d90d2ee5.js → index-DqtyKhzu.js} +120 -27
- package/dist/esm/{index-d90d2ee5.js.map → index-DqtyKhzu.js.map} +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/internal.js +3 -3
- package/dist/esm/internal.js.map +1 -1
- package/dist/index.webworker.js +124 -70
- package/dist/index.webworker.js.map +1 -1
- package/dist/node/index.js +1 -1
- package/dist/node/internal.js +1 -1
- package/dist/node/internal.js.map +1 -1
- package/dist/node/{totp-9e84e53d.js → totp-D8cjDKiH.js} +30 -47
- package/dist/node/{totp-9e84e53d.js.map → totp-D8cjDKiH.js.map} +1 -1
- package/dist/node-esm/index.js +1 -1
- package/dist/node-esm/internal.js +3 -3
- package/dist/node-esm/internal.js.map +1 -1
- package/dist/node-esm/{totp-65577477.js → totp-BkwAJFrn.js} +31 -48
- package/dist/node-esm/{totp-65577477.js.map → totp-BkwAJFrn.js.map} +1 -1
- package/dist/rn/{index-7d302f10.js → index-BzcHGbdh.js} +24 -2
- package/dist/rn/{index-7d302f10.js.map → index-BzcHGbdh.js.map} +1 -1
- package/dist/rn/index.js +7 -1
- package/dist/rn/index.js.map +1 -1
- package/dist/rn/internal.js +96 -25
- package/dist/rn/internal.js.map +1 -1
- package/dist/web-extension-cjs/index.js +2 -1
- package/dist/web-extension-cjs/index.js.map +1 -1
- package/dist/web-extension-cjs/internal.js +1 -1
- package/dist/web-extension-cjs/internal.js.map +1 -1
- package/dist/web-extension-cjs/{register-1fdfc769.js → register-Bk5zU3vt.js} +119 -26
- package/dist/{web-extension-esm/register-293ebff1.js.map → web-extension-cjs/register-Bk5zU3vt.js.map} +1 -1
- package/dist/web-extension-esm/index.js +4 -3
- package/dist/web-extension-esm/index.js.map +1 -1
- package/dist/web-extension-esm/internal.js +3 -3
- package/dist/web-extension-esm/internal.js.map +1 -1
- package/dist/web-extension-esm/{register-293ebff1.js → register-CGKCII54.js} +120 -27
- package/dist/{web-extension-cjs/register-1fdfc769.js.map → web-extension-esm/register-CGKCII54.js.map} +1 -1
- package/package.json +13 -12
- package/dist/cordova/popup_redirect-167cbb8f.js.map +0 -1
package/dist/rn/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var app = require('@firebase/app');
|
|
6
|
-
var index = require('./index-
|
|
6
|
+
var index = require('./index-BzcHGbdh.js');
|
|
7
7
|
require('@firebase/util');
|
|
8
8
|
require('@firebase/component');
|
|
9
9
|
require('@firebase/logger');
|
|
@@ -114,6 +114,12 @@ function getReactNativePersistence(storage) {
|
|
|
114
114
|
* See the License for the specific language governing permissions and
|
|
115
115
|
* limitations under the License.
|
|
116
116
|
*/
|
|
117
|
+
/**
|
|
118
|
+
* This is the file that people using React Native will actually import. You
|
|
119
|
+
* should only include this file if you have something specific about your
|
|
120
|
+
* implementation that mandates having a separate entrypoint. Otherwise you can
|
|
121
|
+
* just use index.ts
|
|
122
|
+
*/
|
|
117
123
|
const NO_PERSISTENCE_WARNING = `
|
|
118
124
|
You are initializing Firebase Auth for React Native without providing
|
|
119
125
|
AsyncStorage. Auth state will default to memory persistence and will not
|
package/dist/rn/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/platform_react_native/persistence/react_native.ts","../../index.rn.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2019 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Persistence, ReactNativeAsyncStorage } from '../../model/public_types';\n\nimport {\n PersistenceInternal,\n PersistenceType,\n PersistenceValue,\n STORAGE_AVAILABLE_KEY,\n StorageEventListener\n} from '../../core/persistence';\n\n/**\n * Returns a persistence object that wraps `AsyncStorage` imported from\n * `react-native` or `@react-native-async-storage/async-storage`, and can\n * be used in the persistence dependency field in {@link initializeAuth}.\n *\n * @example\n * ```javascript\n * import { initializeAuth, getReactNativePersistence } from 'firebase/auth';\n *\n * // For @react-native-async-storage/async-storage v3:\n * import { createAsyncStorage } from '@react-native-async-storage/async-storage';\n * const appStorage = createAsyncStorage('app');\n * const persistence = getReactNativePersistence(appStorage);\n *\n * // For @react-native-async-storage/async-storage v2:\n * // import ReactNativeAsyncStorage from '@react-native-async-storage/async-storage';\n * // const persistence = getReactNativePersistence(ReactNativeAsyncStorage);\n *\n * // Then, initialize auth:\n * const auth = initializeAuth(app, {\n * persistence\n * });\n * ```\n *\n * @public\n */\nexport function getReactNativePersistence(\n storage: ReactNativeAsyncStorage\n): Persistence {\n // In the _getInstance() implementation (see src/core/persistence/index.ts),\n // we expect each \"externs.Persistence\" object passed to us by the user to\n // be able to be instantiated (as a class) using \"new\". That function also\n // expects the constructor to be empty. Since ReactNativeStorage requires the\n // underlying storage layer, we need to be able to create subclasses\n // (closures, essentially) that have the storage layer but empty constructor.\n return class implements PersistenceInternal {\n static type: 'LOCAL' = 'LOCAL';\n readonly type: PersistenceType = PersistenceType.LOCAL;\n\n async _isAvailable(): Promise<boolean> {\n try {\n if (!storage) {\n return false;\n }\n await storage.setItem(STORAGE_AVAILABLE_KEY, '1');\n await storage.removeItem(STORAGE_AVAILABLE_KEY);\n return true;\n } catch {\n return false;\n }\n }\n\n _set(key: string, value: PersistenceValue): Promise<void> {\n return storage.setItem(key, JSON.stringify(value));\n }\n\n async _get<T extends PersistenceValue>(key: string): Promise<T | null> {\n const json = await storage.getItem(key);\n return json ? JSON.parse(json) : null;\n }\n\n _remove(key: string): Promise<void> {\n return storage.removeItem(key);\n }\n\n _addListener(_key: string, _listener: StorageEventListener): void {\n // Listeners are not supported for React Native storage.\n return;\n }\n\n _removeListener(_key: string, _listener: StorageEventListener): void {\n // Listeners are not supported for React Native storage.\n return;\n }\n };\n}\n","/**\n * @license\n * Copyright 2017 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * This is the file that people using React Native will actually import. You\n * should only include this file if you have something specific about your\n * implementation that mandates having a separate entrypoint. Otherwise you can\n * just use index.ts\n */\n\nimport { FirebaseApp, getApp, _getProvider } from '@firebase/app';\nimport { Auth, Dependencies } from './src/model/public_types';\n\nimport { initializeAuth as initializeAuthOriginal } from './src';\nimport { registerAuth } from './src/core/auth/register';\nimport { ClientPlatform } from './src/core/util/version';\nimport { _logWarn } from './src/core/util/log';\n\n// Core functionality shared by all clients\nexport * from './index.shared';\n\n// Export some Phone symbols\n// providers\nexport { PhoneAuthProvider } from './src/platform_browser/providers/phone';\n\n// strategies\nexport {\n signInWithPhoneNumber,\n linkWithPhoneNumber,\n reauthenticateWithPhoneNumber,\n updatePhoneNumber\n} from './src/platform_browser/strategies/phone';\n\n// MFA\nexport { PhoneMultiFactorGenerator } from './src/platform_browser/mfa/assertions/phone';\nexport {\n TotpMultiFactorGenerator,\n TotpSecret\n} from './src/mfa/assertions/totp';\n\nexport { getReactNativePersistence } from './src/platform_react_native/persistence/react_native';\n\nconst NO_PERSISTENCE_WARNING = `\nYou are initializing Firebase Auth for React Native without providing\nAsyncStorage. Auth state will default to memory persistence and will not\npersist between sessions. In order to persist auth state, install the package\n\"@react-native-async-storage/async-storage\" and provide it to\ninitializeAuth:\n\nimport { initializeAuth, getReactNativePersistence } from 'firebase/auth';\n\n// For @react-native-async-storage/async-storage v3:\nimport { createAsyncStorage } from '@react-native-async-storage/async-storage';\nconst appStorage = createAsyncStorage(\"app\");\nconst persistence = getReactNativePersistence(appStorage);\n\n/*\n// For @react-native-async-storage/async-storage v2:\nimport ReactNativeAsyncStorage from '@react-native-async-storage/async-storage';\nconst persistence = getReactNativePersistence(ReactNativeAsyncStorage);\n*/\n\n// Then, initialize auth:\nconst auth = initializeAuth(app, {\n persistence\n});\n`;\n\nexport function getAuth(app: FirebaseApp = getApp()): Auth {\n const provider = _getProvider(app, 'auth');\n\n if (provider.isInitialized()) {\n return provider.getImmediate();\n }\n\n // Only warn if getAuth() is called before initializeAuth()\n _logWarn(NO_PERSISTENCE_WARNING);\n\n return initializeAuthOriginal(app);\n}\n\n/**\n * Wrapper around base `initializeAuth()` for RN users only, which\n * shows the warning message if no persistence is provided.\n * Double-checked potential collision with `export * from './index.shared'`\n * as `./index.shared` also exports `initializeAuth()`, and the final\n * bundle does correctly export only this `initializeAuth()` function\n * and not the one from index.shared.\n */\nexport function initializeAuth(app: FirebaseApp, deps?: Dependencies): Auth {\n if (!deps?.persistence) {\n _logWarn(NO_PERSISTENCE_WARNING);\n }\n return initializeAuthOriginal(app, deps);\n}\n\nregisterAuth(ClientPlatform.REACT_NATIVE);\n"],"names":["STORAGE_AVAILABLE_KEY","app","getApp","_getProvider","_logWarn","initializeAuthOriginal","registerAuth"],"mappings":";;;;;;;;;;AAAA;;;;;;;;;;;;;;;AAeG;AAYH;;;;;;;;;;;;;;;;;;;;;;;;;AAyBG;AACG,SAAU,yBAAyB,CACvC,OAAgC,EAAA;;;;;;;;IAQhC,
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/platform_react_native/persistence/react_native.ts","../../index.rn.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2019 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Persistence, ReactNativeAsyncStorage } from '../../model/public_types';\n\nimport {\n PersistenceInternal,\n PersistenceType,\n PersistenceValue,\n STORAGE_AVAILABLE_KEY,\n StorageEventListener\n} from '../../core/persistence';\n\n/**\n * Returns a persistence object that wraps `AsyncStorage` imported from\n * `react-native` or `@react-native-async-storage/async-storage`, and can\n * be used in the persistence dependency field in {@link initializeAuth}.\n *\n * @example\n * ```javascript\n * import { initializeAuth, getReactNativePersistence } from 'firebase/auth';\n *\n * // For @react-native-async-storage/async-storage v3:\n * import { createAsyncStorage } from '@react-native-async-storage/async-storage';\n * const appStorage = createAsyncStorage('app');\n * const persistence = getReactNativePersistence(appStorage);\n *\n * // For @react-native-async-storage/async-storage v2:\n * // import ReactNativeAsyncStorage from '@react-native-async-storage/async-storage';\n * // const persistence = getReactNativePersistence(ReactNativeAsyncStorage);\n *\n * // Then, initialize auth:\n * const auth = initializeAuth(app, {\n * persistence\n * });\n * ```\n *\n * @public\n */\nexport function getReactNativePersistence(\n storage: ReactNativeAsyncStorage\n): Persistence {\n // In the _getInstance() implementation (see src/core/persistence/index.ts),\n // we expect each \"externs.Persistence\" object passed to us by the user to\n // be able to be instantiated (as a class) using \"new\". That function also\n // expects the constructor to be empty. Since ReactNativeStorage requires the\n // underlying storage layer, we need to be able to create subclasses\n // (closures, essentially) that have the storage layer but empty constructor.\n return class implements PersistenceInternal {\n static type: 'LOCAL' = 'LOCAL';\n readonly type: PersistenceType = PersistenceType.LOCAL;\n\n async _isAvailable(): Promise<boolean> {\n try {\n if (!storage) {\n return false;\n }\n await storage.setItem(STORAGE_AVAILABLE_KEY, '1');\n await storage.removeItem(STORAGE_AVAILABLE_KEY);\n return true;\n } catch {\n return false;\n }\n }\n\n _set(key: string, value: PersistenceValue): Promise<void> {\n return storage.setItem(key, JSON.stringify(value));\n }\n\n async _get<T extends PersistenceValue>(key: string): Promise<T | null> {\n const json = await storage.getItem(key);\n return json ? JSON.parse(json) : null;\n }\n\n _remove(key: string): Promise<void> {\n return storage.removeItem(key);\n }\n\n _addListener(_key: string, _listener: StorageEventListener): void {\n // Listeners are not supported for React Native storage.\n return;\n }\n\n _removeListener(_key: string, _listener: StorageEventListener): void {\n // Listeners are not supported for React Native storage.\n return;\n }\n };\n}\n","/**\n * @license\n * Copyright 2017 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * This is the file that people using React Native will actually import. You\n * should only include this file if you have something specific about your\n * implementation that mandates having a separate entrypoint. Otherwise you can\n * just use index.ts\n */\n\nimport { FirebaseApp, getApp, _getProvider } from '@firebase/app';\nimport { Auth, Dependencies } from './src/model/public_types';\n\nimport { initializeAuth as initializeAuthOriginal } from './src';\nimport { registerAuth } from './src/core/auth/register';\nimport { ClientPlatform } from './src/core/util/version';\nimport { _logWarn } from './src/core/util/log';\n\n// Core functionality shared by all clients\nexport * from './index.shared';\n\n// Export some Phone symbols\n// providers\nexport { PhoneAuthProvider } from './src/platform_browser/providers/phone';\n\n// strategies\nexport {\n signInWithPhoneNumber,\n linkWithPhoneNumber,\n reauthenticateWithPhoneNumber,\n updatePhoneNumber\n} from './src/platform_browser/strategies/phone';\n\n// MFA\nexport { PhoneMultiFactorGenerator } from './src/platform_browser/mfa/assertions/phone';\nexport {\n TotpMultiFactorGenerator,\n TotpSecret\n} from './src/mfa/assertions/totp';\n\nexport { getReactNativePersistence } from './src/platform_react_native/persistence/react_native';\n\nconst NO_PERSISTENCE_WARNING = `\nYou are initializing Firebase Auth for React Native without providing\nAsyncStorage. Auth state will default to memory persistence and will not\npersist between sessions. In order to persist auth state, install the package\n\"@react-native-async-storage/async-storage\" and provide it to\ninitializeAuth:\n\nimport { initializeAuth, getReactNativePersistence } from 'firebase/auth';\n\n// For @react-native-async-storage/async-storage v3:\nimport { createAsyncStorage } from '@react-native-async-storage/async-storage';\nconst appStorage = createAsyncStorage(\"app\");\nconst persistence = getReactNativePersistence(appStorage);\n\n/*\n// For @react-native-async-storage/async-storage v2:\nimport ReactNativeAsyncStorage from '@react-native-async-storage/async-storage';\nconst persistence = getReactNativePersistence(ReactNativeAsyncStorage);\n*/\n\n// Then, initialize auth:\nconst auth = initializeAuth(app, {\n persistence\n});\n`;\n\nexport function getAuth(app: FirebaseApp = getApp()): Auth {\n const provider = _getProvider(app, 'auth');\n\n if (provider.isInitialized()) {\n return provider.getImmediate();\n }\n\n // Only warn if getAuth() is called before initializeAuth()\n _logWarn(NO_PERSISTENCE_WARNING);\n\n return initializeAuthOriginal(app);\n}\n\n/**\n * Wrapper around base `initializeAuth()` for RN users only, which\n * shows the warning message if no persistence is provided.\n * Double-checked potential collision with `export * from './index.shared'`\n * as `./index.shared` also exports `initializeAuth()`, and the final\n * bundle does correctly export only this `initializeAuth()` function\n * and not the one from index.shared.\n */\nexport function initializeAuth(app: FirebaseApp, deps?: Dependencies): Auth {\n if (!deps?.persistence) {\n _logWarn(NO_PERSISTENCE_WARNING);\n }\n return initializeAuthOriginal(app, deps);\n}\n\nregisterAuth(ClientPlatform.REACT_NATIVE);\n"],"names":["STORAGE_AVAILABLE_KEY","app","getApp","_getProvider","_logWarn","initializeAuthOriginal","registerAuth"],"mappings":";;;;;;;;;;AAAA;;;;;;;;;;;;;;;AAeG;AAYH;;;;;;;;;;;;;;;;;;;;;;;;;AAyBG;AACG,SAAU,yBAAyB,CACvC,OAAgC,EAAA;;;;;;;;IAQhC,OAAA,EAAA,GAAO,MAAA;AAAA,YAAA,WAAA,GAAA;AAEI,gBAAA,IAAA,CAAA,IAAI,GAAA,OAAA;YAqCf;AAnCE,YAAA,MAAM,YAAY,GAAA;AAChB,gBAAA,IAAI;oBACF,IAAI,CAAC,OAAO,EAAE;AACZ,wBAAA,OAAO,KAAK;oBACd;oBACA,MAAM,OAAO,CAAC,OAAO,CAACA,2BAAqB,EAAE,GAAG,CAAC;AACjD,oBAAA,MAAM,OAAO,CAAC,UAAU,CAACA,2BAAqB,CAAC;AAC/C,oBAAA,OAAO,IAAI;gBACb;AAAE,gBAAA,MAAM;AACN,oBAAA,OAAO,KAAK;gBACd;YACF;YAEA,IAAI,CAAC,GAAW,EAAE,KAAuB,EAAA;AACvC,gBAAA,OAAO,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;YACpD;YAEA,MAAM,IAAI,CAA6B,GAAW,EAAA;gBAChD,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC;AACvC,gBAAA,OAAO,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI;YACvC;AAEA,YAAA,OAAO,CAAC,GAAW,EAAA;AACjB,gBAAA,OAAO,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC;YAChC;YAEA,YAAY,CAAC,IAAY,EAAE,SAA+B,EAAA;;gBAExD;YACF;YAEA,eAAe,CAAC,IAAY,EAAE,SAA+B,EAAA;;gBAE3D;YACF;AACD,SAAA;AAtCQ,QAAA,EAAA,CAAA,IAAI,GAAY,OAAQ;AAsC/B,QAAA,EAAA;AACJ;;ACtGA;;;;;;;;;;;;;;;AAeG;AAEH;;;;;AAKG;AAkCH,MAAM,sBAAsB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;CAwB9B;AAEK,SAAU,OAAO,CAACC,KAAA,GAAmBC,UAAM,EAAE,EAAA;IACjD,MAAM,QAAQ,GAAGC,gBAAY,CAACF,KAAG,EAAE,MAAM,CAAC;AAE1C,IAAA,IAAI,QAAQ,CAAC,aAAa,EAAE,EAAE;AAC5B,QAAA,OAAO,QAAQ,CAAC,YAAY,EAAE;IAChC;;IAGAG,cAAQ,CAAC,sBAAsB,CAAC;AAEhC,IAAA,OAAOC,oBAAsB,CAACJ,KAAG,CAAC;AACpC;AAEA;;;;;;;AAOG;AACG,SAAU,cAAc,CAAC,GAAgB,EAAE,IAAmB,EAAA;AAClE,IAAA,IAAI,CAAC,IAAI,EAAE,WAAW,EAAE;QACtBG,cAAQ,CAAC,sBAAsB,CAAC;IAClC;AACA,IAAA,OAAOC,oBAAsB,CAAC,GAAG,EAAE,IAAI,CAAC;AAC1C;AAEAC,kBAAY,iDAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/rn/internal.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var index = require('./index-
|
|
5
|
+
var index = require('./index-BzcHGbdh.js');
|
|
6
6
|
var util = require('@firebase/util');
|
|
7
7
|
var app = require('@firebase/app');
|
|
8
8
|
require('@firebase/component');
|
|
@@ -814,6 +814,28 @@ function _deleteObject(db, key) {
|
|
|
814
814
|
const _POLLING_INTERVAL_MS = 800;
|
|
815
815
|
const _TRANSACTION_RETRY_COUNT = 3;
|
|
816
816
|
class IndexedDBLocalPersistence {
|
|
817
|
+
registerLifecycleListeners() {
|
|
818
|
+
if (typeof window !== 'undefined' &&
|
|
819
|
+
typeof window.addEventListener === 'function') {
|
|
820
|
+
window.addEventListener('pagehide', this.onPageHide);
|
|
821
|
+
window.addEventListener('pageshow', this.onPageShow);
|
|
822
|
+
}
|
|
823
|
+
if (typeof document !== 'undefined' &&
|
|
824
|
+
typeof document.addEventListener === 'function') {
|
|
825
|
+
document.addEventListener('visibilitychange', this.onVisibilityChange);
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
unregisterLifecycleListeners() {
|
|
829
|
+
if (typeof window !== 'undefined' &&
|
|
830
|
+
typeof window.removeEventListener === 'function') {
|
|
831
|
+
window.removeEventListener('pagehide', this.onPageHide);
|
|
832
|
+
window.removeEventListener('pageshow', this.onPageShow);
|
|
833
|
+
}
|
|
834
|
+
if (typeof document !== 'undefined' &&
|
|
835
|
+
typeof document.removeEventListener === 'function') {
|
|
836
|
+
document.removeEventListener('visibilitychange', this.onVisibilityChange);
|
|
837
|
+
}
|
|
838
|
+
}
|
|
817
839
|
constructor() {
|
|
818
840
|
this.type = "LOCAL" /* PersistenceType.LOCAL */;
|
|
819
841
|
this.dbPromise = null;
|
|
@@ -823,16 +845,46 @@ class IndexedDBLocalPersistence {
|
|
|
823
845
|
// setTimeout return value is platform specific
|
|
824
846
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
825
847
|
this.pollTimer = null;
|
|
848
|
+
this.isHiding = false;
|
|
826
849
|
this.pendingWrites = 0;
|
|
827
850
|
this.receiver = null;
|
|
828
851
|
this.sender = null;
|
|
829
852
|
this.serviceWorkerReceiverAvailable = false;
|
|
830
853
|
this.activeServiceWorker = null;
|
|
854
|
+
this.onPageHide = () => {
|
|
855
|
+
this.isHiding = true;
|
|
856
|
+
this.stopPolling();
|
|
857
|
+
if (this.dbPromise) {
|
|
858
|
+
this.dbPromise.then(db => db.close()).catch(() => { });
|
|
859
|
+
this.dbPromise = null;
|
|
860
|
+
}
|
|
861
|
+
};
|
|
862
|
+
this.onPageShow = () => {
|
|
863
|
+
if (this.isHiding) {
|
|
864
|
+
this.isHiding = false;
|
|
865
|
+
if (Object.keys(this.listeners).length > 0) {
|
|
866
|
+
this.startPolling();
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
};
|
|
870
|
+
this.onVisibilityChange = () => {
|
|
871
|
+
if (typeof document !== 'undefined') {
|
|
872
|
+
if (document.visibilityState === 'hidden') {
|
|
873
|
+
this.onPageHide();
|
|
874
|
+
}
|
|
875
|
+
else if (document.visibilityState === 'visible') {
|
|
876
|
+
this.onPageShow();
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
};
|
|
831
880
|
// Fire & forget the service worker registration as it may never resolve
|
|
832
881
|
this._workerInitializationPromise =
|
|
833
882
|
this.initializeServiceWorkerMessaging().then(() => { }, () => { });
|
|
834
883
|
}
|
|
835
884
|
async _openDb() {
|
|
885
|
+
if (this.isHiding) {
|
|
886
|
+
throw new Error('Database is closing/hidden');
|
|
887
|
+
}
|
|
836
888
|
if (this.dbPromise) {
|
|
837
889
|
return this.dbPromise;
|
|
838
890
|
}
|
|
@@ -850,6 +902,9 @@ class IndexedDBLocalPersistence {
|
|
|
850
902
|
return await op(db);
|
|
851
903
|
}
|
|
852
904
|
catch (e) {
|
|
905
|
+
if (this.isHiding) {
|
|
906
|
+
throw e;
|
|
907
|
+
}
|
|
853
908
|
if (numAttempts++ > _TRANSACTION_RETRY_COUNT) {
|
|
854
909
|
throw e;
|
|
855
910
|
}
|
|
@@ -979,37 +1034,51 @@ class IndexedDBLocalPersistence {
|
|
|
979
1034
|
});
|
|
980
1035
|
}
|
|
981
1036
|
async _poll() {
|
|
982
|
-
|
|
983
|
-
const result = await this._withRetries((db) => {
|
|
984
|
-
const getAllRequest = getObjectStore(db, false).getAll();
|
|
985
|
-
return new DBPromise(getAllRequest).toPromise();
|
|
986
|
-
});
|
|
987
|
-
if (!result) {
|
|
1037
|
+
if (this.isHiding) {
|
|
988
1038
|
return [];
|
|
989
1039
|
}
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1040
|
+
try {
|
|
1041
|
+
// TODO: check if we need to fallback if getAll is not supported
|
|
1042
|
+
const result = await this._withRetries((db) => {
|
|
1043
|
+
const getAllRequest = getObjectStore(db, false).getAll();
|
|
1044
|
+
return new DBPromise(getAllRequest).toPromise();
|
|
1045
|
+
});
|
|
1046
|
+
if (this.isHiding) {
|
|
1047
|
+
return [];
|
|
1048
|
+
}
|
|
1049
|
+
if (!result) {
|
|
1050
|
+
return [];
|
|
1051
|
+
}
|
|
1052
|
+
// If we have pending writes in progress abort, we'll get picked up on the next poll
|
|
1053
|
+
if (this.pendingWrites !== 0) {
|
|
1054
|
+
return [];
|
|
1055
|
+
}
|
|
1056
|
+
const keys = [];
|
|
1057
|
+
const keysInResult = new Set();
|
|
1058
|
+
if (result.length !== 0) {
|
|
1059
|
+
for (const { fbase_key: key, value } of result) {
|
|
1060
|
+
keysInResult.add(key);
|
|
1061
|
+
if (JSON.stringify(this.localCache[key]) !== JSON.stringify(value)) {
|
|
1062
|
+
this.notifyListeners(key, value);
|
|
1063
|
+
keys.push(key);
|
|
1064
|
+
}
|
|
1002
1065
|
}
|
|
1003
1066
|
}
|
|
1067
|
+
for (const localKey of Object.keys(this.localCache)) {
|
|
1068
|
+
if (this.localCache[localKey] && !keysInResult.has(localKey)) {
|
|
1069
|
+
// Deleted
|
|
1070
|
+
this.notifyListeners(localKey, null);
|
|
1071
|
+
keys.push(localKey);
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
return keys;
|
|
1004
1075
|
}
|
|
1005
|
-
|
|
1006
|
-
if (this.
|
|
1007
|
-
|
|
1008
|
-
this.notifyListeners(localKey, null);
|
|
1009
|
-
keys.push(localKey);
|
|
1076
|
+
catch (e) {
|
|
1077
|
+
if (!this.isHiding) {
|
|
1078
|
+
index._logWarn(`Firebase Auth cross-tab polling failed with error: ${e}`);
|
|
1010
1079
|
}
|
|
1080
|
+
return [];
|
|
1011
1081
|
}
|
|
1012
|
-
return keys;
|
|
1013
1082
|
}
|
|
1014
1083
|
notifyListeners(key, newValue) {
|
|
1015
1084
|
this.localCache[key] = newValue;
|
|
@@ -1033,6 +1102,7 @@ class IndexedDBLocalPersistence {
|
|
|
1033
1102
|
_addListener(key, listener) {
|
|
1034
1103
|
if (Object.keys(this.listeners).length === 0) {
|
|
1035
1104
|
this.startPolling();
|
|
1105
|
+
this.registerLifecycleListeners();
|
|
1036
1106
|
}
|
|
1037
1107
|
if (!this.listeners[key]) {
|
|
1038
1108
|
this.listeners[key] = new Set();
|
|
@@ -1050,6 +1120,7 @@ class IndexedDBLocalPersistence {
|
|
|
1050
1120
|
}
|
|
1051
1121
|
if (Object.keys(this.listeners).length === 0) {
|
|
1052
1122
|
this.stopPolling();
|
|
1123
|
+
this.unregisterLifecycleListeners();
|
|
1053
1124
|
}
|
|
1054
1125
|
}
|
|
1055
1126
|
}
|