Skip to content

Remove dependency on @react-native-async-storage/async-storage #7570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/eleven-lamps-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@firebase/auth': minor
'firebase': minor
---

Remove dependency on @react-native-async-storage/async-storage and add warnings to remind React Native users to manually import it.
36 changes: 28 additions & 8 deletions packages/auth/index.rn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@
*/

import { FirebaseApp, getApp, _getProvider } from '@firebase/app';
import { Auth } from './src/model/public_types';
import { Auth, Dependencies } from './src/model/public_types';

import { initializeAuth } from './src';
import { initializeAuth as initializeAuthOriginal } from './src';
import { registerAuth } from './src/core/auth/register';
import { ClientPlatform } from './src/core/util/version';
import { getReactNativePersistence } from './src/platform_react_native/persistence/react_native';
import ReactNativeAsyncStorage from '@react-native-async-storage/async-storage';
import { _logWarn } from './src/core/util/log';

// Core functionality shared by all clients
export * from './index.shared';
Expand All @@ -49,7 +48,21 @@ export {
// MFA
export { PhoneMultiFactorGenerator } from './src/platform_browser/mfa/assertions/phone';

export { getReactNativePersistence };
export { getReactNativePersistence } from './src/platform_react_native/persistence/react_native';

const NO_PERSISTENCE_WARNING = `
You are initializing Firebase Auth for React Native without providing
AsyncStorage. Auth state will default to memory persistence and will not
persist between sessions. In order to persist auth state, install the package
"@react-native-async-storage/async-storage" and provide it to
initializeAuth:

import { initializeAuth, getReactNativePersistence } from 'firebase/auth';
import ReactNativeAsyncStorage from '@react-native-async-storage/async-storage';
const auth = initializeAuth(app, {
persistence: getReactNativePersistence(ReactNativeAsyncStorage)
});
`;

export function getAuth(app: FirebaseApp = getApp()): Auth {
const provider = _getProvider(app, 'auth');
Expand All @@ -58,9 +71,16 @@ export function getAuth(app: FirebaseApp = getApp()): Auth {
return provider.getImmediate();
}

return initializeAuth(app, {
persistence: getReactNativePersistence(ReactNativeAsyncStorage)
});
_logWarn(NO_PERSISTENCE_WARNING);

return initializeAuthOriginal(app);
}

export function initializeAuth(app: FirebaseApp, deps?: Dependencies): Auth {
if (!deps?.persistence) {
_logWarn(NO_PERSISTENCE_WARNING);
}
return initializeAuthOriginal(app, deps);
}

registerAuth(ClientPlatform.REACT_NATIVE);
9 changes: 7 additions & 2 deletions packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,18 @@
"typings:public": "node ../../scripts/build/use_typings.js ./dist/auth-public.d.ts"
},
"peerDependencies": {
"@firebase/app": "0.x"
"@firebase/app": "0.x",
"@react-native-async-storage/async-storage": "^1.18.1"
},
"peerDependenciesMeta": {
"@react-native-async-storage/async-storage": {
"optional": true
}
},
"dependencies": {
"@firebase/component": "0.6.4",
"@firebase/logger": "0.4.0",
"@firebase/util": "1.9.3",
"@react-native-async-storage/async-storage": "^1.18.1",
"node-fetch": "2.6.7",
"tslib": "^2.1.0"
},
Expand Down
14 changes: 0 additions & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3263,13 +3263,6 @@
resolved "https://registry.npmjs.org/@protobufjs/utf8/-/utf8-1.1.0.tgz#a777360b5b39a1a2e5106f8e858f2fd2d060c570"
integrity sha1-p3c2C1s5oaLlEG+OhY8v0tBgxXA=

"@react-native-async-storage/async-storage@^1.18.1":
version "1.19.0"
resolved "https://registry.npmjs.org/@react-native-async-storage/async-storage/-/async-storage-1.19.0.tgz#594aca9c20924b7955d62cf43797b4187e1e6cf8"
integrity sha512-xOFkz/FaQctD6yNJDur+WnHdSTigOs3pTz6HmfC8X8PYwcnnN3R9UxuWiwsfK8vvT2WioAxUkQt3lB7GySNA2w==
dependencies:
merge-options "^3.0.4"

"@rollup/[email protected]":
version "3.1.9"
resolved "https://registry.npmjs.org/@rollup/plugin-alias/-/plugin-alias-3.1.9.tgz#a5d267548fe48441f34be8323fb64d1d4a1b3fdf"
Expand Down Expand Up @@ -12290,13 +12283,6 @@ [email protected]:
resolved "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz#b00aaa556dd8b44568150ec9d1b953f3f90cbb61"
integrity sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E=

merge-options@^3.0.4:
version "3.0.4"
resolved "https://registry.npmjs.org/merge-options/-/merge-options-3.0.4.tgz#84709c2aa2a4b24c1981f66c179fe5565cc6dbb7"
integrity sha512-2Sug1+knBjkaMsMgf1ctR1Ujx+Ayku4EdJN4Z+C2+JzoeF7A3OZ9KM2GY0CpQS51NR61LTurMJrRKPhSs3ZRTQ==
dependencies:
is-plain-obj "^2.1.0"

merge-stream@^2.0.0:
version "2.0.0"
resolved "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz#52823629a14dd00c9770fb6ad47dc6310f2c1f60"
Expand Down