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 1 commit
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
5 changes: 5 additions & 0 deletions .changeset/eleven-lamps-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@firebase/auth': minor
---

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

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 @@ -51,16 +51,37 @@ export { PhoneMultiFactorGenerator } from './src/platform_browser/mfa/assertions

export { getReactNativePersistence };

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');

if (provider.isInitialized()) {
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);
1 change: 0 additions & 1 deletion packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@
"@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