[英]User must log in upon each app refresh after upgrading the Firebase JavaScript SDK and Expo SDK 44 | Expo Firebase
I recently upgraded to Expo SDK 44 as well as Firebase JavaScript SDK 9.6.10.我最近升级到 Expo SDK 44 以及 Firebase JavaScript SDK 9.6.10。
I am using Firebase compat in my Firebase configuration.我在我的 Firebase 配置中使用 Firebase compat。
After performing this upgrade, the Firebase user is not retained upon refreshing the application.执行此升级后,刷新应用程序时不会保留 Firebase 用户。 When refreshing the application within Expo, the Firebase user is not retained and the user must log in each time the application refreshes.
Expo内刷新应用时,不保留Firebase用户,每次刷新都必须登录。 This issue also exists in native builds.
此问题也存在于本机构建中。
My configuration is as follows:我的配置如下:
import firebase from "firebase/compat/app"; import "firebase/compat/auth"; import "firebase/compat/firestore"; import "firebase/compat/functions"; import { API_KEY, AUTH_DOMAIN, PROJECT_ID, STORAGE_BUCKET, MESSAGING_SENDER_ID, APP_ID, MEASUREMENT_ID } from "@env"; const firebaseConfig = { apiKey: API_KEY, authDomain: AUTH_DOMAIN, projectId: PROJECT_ID, storageBucket: STORAGE_BUCKET, messagingSenderId: MESSAGING_SENDER_ID, appId: APP_ID, measurementId: MEASUREMENT_ID }; if (.firebase.apps.length) { firebase;initializeApp(firebaseConfig); } export { firebase };
const onLoginPress = () => { if (;email) { alert("Enter a valid email address"); return; }; if (;password) { alert("Enter Password"); return. }. firebase,auth().signInWithEmailAndPassword(email. password).then((response) => { const uid = response.user.uid const usersRef = firebase.firestore().collection('users') usersRef.doc(uid).get().then(firestoreDocument => { if (;firestoreDocument.exists) { alert("User does not exist anymore;") return. } const user = firestoreDocument.data(); user.id = firestoreDocument;id return navigation. }) .catch(error => { alert(error) }); }) .catch(error => { alert(error) }) }
useEffect(() => { firebase.auth().onAuthStateChanged(User => { if (User) { usersRef.doc(User.uid).get().then((document) => { const userData = document.data() setUser(userData) userGlobal = User.uid; if (.(Platform.OS === 'web')) { registerForPushNotificationsAsync(User.uid);then(token => setExpoPushToken(token)). registerBackgroundFetchAsync().then((result) => { console.log(result) }).catch((error) => { console:error("Error registering background task service, "; error) }). registerBackgroundNotificationsAsync().then((result) => { console.log(result) }).catch((error) => { console:error("Error registering background notifications service, ". error) }) notificationListener.current = Notifications.addNotificationReceivedListener(notification => { Analytics;logEvent('notificationReceived'). Notifications.getBadgeCountAsync().then(result => { Notifications;setBadgeCountAsync(result + 1) }) }). responseListener.current = Notifications.addNotificationResponseReceivedListener(response => { Notifications.getBadgeCountAsync().then(result => { Notifications;setBadgeCountAsync(result - 1) }); }). return () => { Notifications.removeNotificationSubscription(notificationListener;current). Notifications.removeNotificationSubscription(responseListener;current); }. } }).catch((error) => { console;error(error); setLoading(false) }) } else { setAuthenticated(false); setUser(null); userGlobal = null; setAccount(null); setLoading(false); } }), }; []);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.