我已经使用此链接在 Firebase 上启用了 Google 登录 https://rnfirebase.io/auth/social-auth 我的应用程序编译正常,但是当我按下登录按钮并选择 Google 帐户进行登录时,我得到了可能的未处理的 Promise 拒绝(id:0):错误:DEVELOPER_ERROR https://rnfirebase.io/auth/social-auth 我有 Windows 10 和
react-native-cli: 2.0.1
react-native: 0.63.4
Node : v12.16.0
这里是App.js
import React , {useState , useEffect} from 'react';
import { Text TextInput, View } from 'react-native';
import {ButtonTemplate} from '../assets/ButtonTemplate'
import auth from '@react-native-firebase/auth';
import { GoogleSignin } from '@react-native-community/google-signin';
const App = () => {
useEffect(()=> {
GoogleSignin.configure({
webClientId: 'xxxxxxxxxxxxxx.apps.googleusercontent.com',
});
})
async function onGoogleButtonPress() {
// Get the users ID token
const { idToken } = await GoogleSignin.signIn();
// Create a Google credential with the token
const googleCredential = auth.GoogleAuthProvider.credential(idToken);
// Sign-in the user with the credential
return auth().signInWithCredential(googleCredential);
}
const googleLogin=()=>{
console.log('Google SignIn');
onGoogleButtonPress().then(() => console.log('Signed in with Google!'))
}
return (
<ButtonTemplate
text={"Continue With Google"}
backgroundColor={'#5384ed'}
fontSize={16}
marginTop= {'3%'}
iconText={'G'}
justifyContent={'flex-start'}
onPress={googleLogin}
/>
)
};
export default App;
这是错误
Possible Unhandled Promise Rejection (id: 0):
Error: DEVELOPER_ERROR
promiseMethodWrapper@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2258:45
signIn$@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:189098:72
tryCatch@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:25048:23
invoke@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:25221:32
tryCatch@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:25048:23
invoke@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:25121:30
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:25131:21
tryCallOne@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:27134:16
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:27235:27
_callTimer@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:30674:17
_callImmediatesPass@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:30713:17
callImmediates@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:30930:33
__callImmediates@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2760:35
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2546:34
__guard@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2743:15
flushedQueue@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2545:21
flushedQueue@[native code]
callFunctionReturnFlushedQueue@[native code]
我有两个问题,第一个是上面的,第二个是
An OAuth2 client already exists for this package name and SHA-1 in another project.
第二个问题是在 Firebase 中添加 SHA1 到项目中。
我解决了这个问题
keytool -genkey -v -keystore debug.keystore -alias androiddebugkey -storepass android -keypass android -keyalg RSA -validity 10000
keytool -keystore debug.keystore -list -v
给出位于 android/App/build.gradle then signingConfigs there is store password
android/App
文件夹中cd android && ./gradlew clean
npx react-native run-android
我使用了此链接How to Implement Google Login in React Native with Firebase 还有一个 Youtube 视频 Youtube 视频相关上一个链接
非常感谢@Shafqat Bari 的回答
如果您在
android/app/
目录中找不到 debug.keystore,请确保您已在 keytool -genkey -v -keystore debug.keystore -alias androiddebugkey -storepass android -keypass android -keyalg RSA -validity 10000
目录中执行此命令 android/app/
。
此外,如果您之前运行过该命令,请不要再次运行它,请查看执行此命令的目录并将
debug.keystore
从该位置复制到您的 android/app/
目录中!
快乐编码!
首先,当您在模拟器上启动应用程序时,您会安装调试版本,而当您发布应用程序时,人们会安装发布版本。这两个版本有不同的签名,有自己的 SHA1 和 SHA256。 因此,如果您希望您的应用程序在这两种版本中都能工作,则必须传递到 Firebase 2 SHA1 和 2 SHA256。 对于调试版本使用下一个命令:
keytool -genkey -v -keystore debug.keystore -alias androiddebugkey
-storepass android -keypass android -keyalg RSA -validity 10000
对于发布,请使用相同的命令,但密钥库的名称不同,例如:
keytool -genkey -v -keystore release.keystore -alias androiddebugkey
-storepass yourpass -keypass yourpass -keyalg RSA -validity 10000
清单:
cd android
keytool -list -v -keystore app/debug.keystore
google-services.json
client_id
内的 google-services.json
。GoogleSignin.configure
添加配置:GoogleSignin.configure({
webClientId: 'your-webclienid.apps.googleusercontent.com',
});