Skip to content

Instantly share code, notes, and snippets.

@keith-kurak
Created June 2, 2023 04:55
Show Gist options
  • Save keith-kurak/62628e661dab6d5452d29a2f3a3bf5a5 to your computer and use it in GitHub Desktop.
Save keith-kurak/62628e661dab6d5452d29a2f3a3bf5a5 to your computer and use it in GitHub Desktop.
Firebase RN auth persistence fix
import { initializeApp } from "firebase/app";
import AsyncStorage from '@react-native-async-storage/async-storage';
import { initializeAuth, getReactNativePersistence } from "firebase/auth"
const firebaseConfig = {
//..
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const reactNativeLocalPersistence =
getReactNativePersistence({
getItem(...args) {
// Called inline to avoid deprecation warnings on startup.
return AsyncStorage.getItem(...args);
},
setItem(...args) {
// Called inline to avoid deprecation warnings on startup.
return AsyncStorage.setItem(...args);
},
removeItem(...args) {
// Called inline to avoid deprecation warnings on startup.
return AsyncStorage.removeItem(...args);
},
});
initializeAuth(app,
{
persistence: reactNativeLocalPersistence
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment