英文:
Firebase signIn issue in React Native Expo production build - Crashes after selecting Google account in SigninScreen
问题
Firebase在React Native Expo生产版本中的登录问题 - 选择Google帐号后崩溃
我在我的React Native应用中遇到了一个严重问题,即在登录过程中选择Google帐号后,应用会在生产版本中突然崩溃,但在开发版本(Expo)中,应用却可以正常工作,没有崩溃。下次应用打开时,checkedSignIn函数正常工作,这意味着登录成功,但在Firestore中未创建文档。
概述:
- 问题特别发生在我的React Native应用的生产版本中。
- 崩溃发生在选择Google帐号后的登录过程中。
- 预期行为是完成登录过程并将用户设置为已登录。
- 在开发版本(Expo)中,应用可以正常工作,没有崩溃或问题。
编辑 [经过进一步记录,似乎代码在这一行停止执行,之后没有显示更多的日志并且应用程序崩溃:]
const { user } = await auth().signInWithCredential(googleCredential);
相关代码:
以下是来自我的useAuth钩子的相关代码片段:
// ...
const signInWithGoogle = async () => {
try {
setLoading(true);
await GoogleSignin.hasPlayServices({ showPlayServicesUpdateDialog: true });
const { idToken } = await GoogleSignin.signIn();
const googleCredential = auth.GoogleAuthProvider.credential(idToken);
const { user } = await auth().signInWithCredential(googleCredential);
await setUserInFirestore(user);
} catch (error) {
setError(error);
console.log("Error signing in with Google:", error);
}
};
// ...
const setUserInFirestore = async (user) => {
const { uid, displayName, email, photoURL } = user;
try {
const userRef = doc(db, "users", uid);
const snapshot = await getDoc(userRef);
if (!snapshot.exists()) {
await setDoc(userRef, {
displayName,
email,
photoURL,
uid,
subscription: null,
});
}
setUser(user);
setUserContext(user);
} catch (error) {
console.log("Error adding user to Firestore:", error.message);
navigation.navigate(routes.WELCOME);
} finally {
setLoading(false);
}
};
版本:
- React Native: 0.71.8
- Expo: ~48.0.15
- @react-native-firebase/app: ^17.4.3
- @react-native-firebase/auth: ^17.4.3
- @react-native-google-signin/google-signin: ^9.0.2
- Firebase: ^9.21.0
英文:
Firebase signIn issue in React Native Expo production build - Crashes after selecting Google account in SigninScreen
I am facing a critical issue in my React Native app where the app crashes abruptly after selecting a Google account during the signin process, but only in the production build. In the development build (Expo), the app works fine without any crashes. The next time the app opens the checkedSignIn function works fine which means sign in was successful but the doc is not created in the firestore.
Overview:
- The issue occurs specifically in the production build of my React Native app.
- The crash happens after selecting a Google account during the signin process.
- The expected behavior is to complete the signin process and setUser() to the logged in user.
- The app works fine in the development build (Expo) without any crashes or issues.
Edit [ after further logging it looks like the code stops at this line as no further logs are shown after this and app crashes: ]
const { user } = await auth().signInWithCredential(googleCredential);
Relevant Code:
Here is the relevant code snippet from my useAuth hook:
// ...
const signInWithGoogle = async () => {
try {
setLoading(true);
await GoogleSignin.hasPlayServices({ showPlayServicesUpdateDialog: true });
const { idToken } = await GoogleSignin.signIn();
const googleCredential = auth.GoogleAuthProvider.credential(idToken);
const { user } = await auth().signInWithCredential(googleCredential);
await setUserInFirestore(user);
} catch (error) {
setError(error);
console.log("Error signing in with Google:", error);
}
};
// ...
const setUserInFirestore = async (user) => {
const { uid, displayName, email, photoURL } = user;
try {
const userRef = doc(db, "users", uid);
const snapshot = await getDoc(userRef);
if (!snapshot.exists()) {
await setDoc(userRef, {
displayName,
email,
photoURL,
uid,
subscription: null,
});
}
setUser(user);
setUserContext(user);
} catch (error) {
console.log("Error adding user to Firestore:", error.message);
navigation.navigate(routes.WELCOME);
} finally {
setLoading(false);
}
};
Versions:
- React Native: 0.71.8
- Expo: ~48.0.15
- @react-native-firebase/app: ^17.4.3
- @react-native-firebase/auth: ^17.4.3
- @react-native-google-signin/google-signin: ^9.0.2
- Firebase: ^9.21.0
答案1
得分: 1
对我来说问题在于我需要打开Xcode并且:
- 进入我的GoogleService-Info.plist文件
- 复制
REVERSED_CLIENT_ID
的值 - 导航到项目的TARGETS并选择我的应用程序
- 选择Info选项卡,然后导航到URL Types部分
- 通过点击加号(+)图标向URL Types部分添加一个新项目
- 将
REVERSED_CLIENT_ID
的值粘贴到URL Schemes字段中。
如果您认为这些说明不够清晰,您可以观看此视频,视频在5:20处演示了这些步骤。
英文:
For me the issue was that I needed to open Xcode and:
- Go to my GoogleService-Info.plist file
- Copy the value of the
REVERSED_CLIENT_ID
- Navigate to the project's TARGETS and select my app
- Select the Info tab and navigate to the URL Types section
- Add a new item to the URL Types section by tapping on the plus (+) icon
- Paste the value of the
REVERSED_CLIENT_ID
in the URL Schemes field.
In case you feel these instructions are not clear enough, you can watch this video that goes through these steps at 5:20
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论