UNPKG

7.85 kBSource Map (JSON)View Raw
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-community/async-storage`, and can\n * be used in the persistence dependency field in {@link initializeAuth}.\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, esentially) 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 * as ReactNative from 'react-native';\n\nimport { FirebaseApp, getApp, _getProvider } from '@firebase/app';\nimport { Auth, Persistence } from './src/model/public_types';\n\nimport { initializeAuth } from './src';\nimport { registerAuth } from './src/core/auth/register';\nimport { ClientPlatform } from './src/core/util/version';\nimport { getReactNativePersistence } from './src/platform_react_native/persistence/react_native';\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';\n\n/**\n * An implementation of {@link Persistence} of type 'LOCAL' for use in React\n * Native environments.\n *\n * @public\n */\nexport const reactNativeLocalPersistence: Persistence =\n getReactNativePersistence({\n getItem(...args) {\n // Called inline to avoid deprecation warnings on startup.\n return ReactNative.AsyncStorage.getItem(...args);\n },\n setItem(...args) {\n // Called inline to avoid deprecation warnings on startup.\n return ReactNative.AsyncStorage.setItem(...args);\n },\n removeItem(...args) {\n // Called inline to avoid deprecation warnings on startup.\n return ReactNative.AsyncStorage.removeItem(...args);\n },\n });\n\nexport {getReactNativePersistence};\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 return initializeAuth(app, {\n persistence: reactNativeLocalPersistence\n });\n}\n\nregisterAuth(ClientPlatform.REACT_NATIVE);\n"],"names":["STORAGE_AVAILABLE_KEY","ReactNative","app","getApp","_getProvider","initializeAuth","registerAuth"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;AA2BA;;;;;;;SAOgB,yBAAyB,CACvC,OAAgC;;;;;;;;IAQhC;YAAO;gBAEI,SAAI,uBAA0C;aAqCxD;YAnCO,8BAAY,GAAlB;;;;;;gCAEI,IAAI,CAAC,OAAO,EAAE;oCACZ,sBAAO,KAAK,EAAC;iCACd;gCACD,qBAAM,OAAO,CAAC,OAAO,CAACA,2BAAqB,EAAE,GAAG,CAAC,EAAA;;gCAAjD,SAAiD,CAAC;gCAClD,qBAAM,OAAO,CAAC,UAAU,CAACA,2BAAqB,CAAC,EAAA;;gCAA/C,SAA+C,CAAC;gCAChD,sBAAO,IAAI,EAAC;;;gCAEZ,sBAAO,KAAK,EAAC;;;;;aAEhB;YAED,sBAAI,GAAJ,UAAK,GAAW,EAAE,KAAuB;gBACvC,OAAO,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;aACpD;YAEK,sBAAI,GAAV,UAAuC,GAAW;;;;;oCACnC,qBAAM,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,EAAA;;gCAAjC,IAAI,GAAG,SAA0B;gCACvC,sBAAO,IAAI,GAAG,IAAI,CAAC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