繁体   English   中英

升级 Firebase JavaScript SDK 和 Expo SDK 44 | 后,用户必须在每次应用程序刷新时登录 Expo Firebase

[英]User must log in upon each app refresh after upgrading the Firebase JavaScript SDK and Expo SDK 44 | Expo Firebase

我最近升级到 Expo SDK 44 以及 Firebase JavaScript SDK 9.6.10。

我在我的 Firebase 配置中使用 Firebase compat。

执行此升级后,刷新应用程序时不会保留 Firebase 用户。 Expo内刷新应用时,不保留Firebase用户,每次刷新都必须登录。 此问题也存在于本机构建中。

我的配置如下:

 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); } }), }; []);

异步存储是从 react-native 内核中提取的,在本机版本 0.64.3 中重构 firebase 9.6.10 以使用模块化导入 (v9) 与使用兼容 (v8) 命名空间解决了此问题。

Expo 警告 - React Native 异步存储

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM