gpt4 book ai didi

javascript - 尝试在 React Native 中使用 GoogleSignIn,然后可能出现未处理的 Promise Rejection(id : Error: DEVELOPER_ERROR

转载 作者:行者123 更新时间:2023-12-05 00:37:22 34 4
gpt4 key购买 nike

我已使用此链接在 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。
我解决了这个问题

  • 删除 debug.keystore
  • 然后通过这个 keytool -genkey -v -keystore debug.keystore -alias androiddebugkey -storepass android -keypass android -keyalg RSA -validity 10000 重新生成它
  • 然后通过这个命令得到 SHA1 和 SHA256 keytool -keystore debug.keystore -list -v在给出位于 android/App/build.gradle then signingConfigs there is store password 中的密码后
  • 在 Firebase 我的项目中添加了 SHA1 和 SHA256
  • 下载最新的 JSON 文件在我的项目中添加最新的 JSON android/App文件夹
  • 然后通过 cd android && ./gradlew clean 清理 gradle
  • 卸载应用程序然后执行npx react-native run-android
  • 现在它的工作:)

  • 我用这个链接 How to Implement Google Login in React Native with Firebase
    还有一个 Youtube 视频 Youtube Video Related Previous Link

    关于javascript - 尝试在 React Native 中使用 GoogleSignIn,然后可能出现未处理的 Promise Rejection(id : Error: DEVELOPER_ERROR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66562391/

    34 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com