[英]Expo react-native app with firebase phone authentication works on web, error on ios simulator and crashes with no warning on Android
[英]React-native expo: google login works on IOS and Android, but doesnt work in web browsers
使用 expo authSession我能够使谷歌登录在 iOS 和 android 上工作(在模拟器中测试),我从谷歌正确地获得了 accessToken 和 idToken 以及所有用户数据。
但是,当我对 web 客户端进行相同的尝试时,它不起作用。 一切都在谷歌云中设置,没有错误出现,我可以成功响应登录到谷歌,但所有数据都是 null:
response.type 是“成功”(见屏幕截图),但身份验证 object 仍然是 null(accessToken 存储在那里用于 iOS 和 Android)。 这是我使用 web 浏览器得到的数据响应,完全没有显示错误: enter image description here
我的代码片段,尝试使用“cliendId”、“webClientId”、“expoClientId”:`
const [request, response, promptAsync] = Google.useIdTokenAuthRequest({
//clientId: "594408663...",
webClientId: "5944086633...",
//expoClientId: "5944086633...",
iosClientId: "5944086633...",
androidClientId: "594408663..."
})
React.useEffect(() => {
if(response?.type == "success") {
console.log('respons', response)
setAccessToken(response.authentication?.accessToken)
setIdToken(response.authentication?.idToken)
----------- FAILS HERE AS AUTHENTICATION IS NULL ------------
accessToken && fetchUserInfo()
}
}, [response, accessToken])
const fetchUserInfo = async () => {
let userInfoResponse = await fetch("https://www.googleapis.com/userinfo/v2/me", {
headers: {
Authorization: `Bearer ${accessToken}`
}
})
// creat firebase user entry
const credential = GoogleAuthProvider.credential(idToken, accessToken)
await signInWithCredential(auth, credential)
// create userdata state
const userData = await userInfoResponse.json()
setUser(userData)
}
`
据我了解,我不必为 web 客户端做任何不同的事情吗? 也许我错过了什么?
也许它很重要:在 chrome 本地主机、macOS 中进行测试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.