世博会:“auth/operation-not-supported-in-this-environment"
我开发了一个 react-native (expo) 移动应用,并尝试使用 google 帐户登录到 firebase,但出现错误:
I develop a react-native (expo) mobile app and try to sign in with a google account to firebase, but I get an error:
"auth/operation-not-supported-in-this-enviroment.此应用程序运行的环境不支持此操作."location.protocol" 必须是 http、https 或 chrome-extension 并且网络存储必须启用"
"auth/operation-not-supported-in-this-enviroment. This operation is not supported in the enviroment this application is running on. "location.protocol" must be http, https or chrome-extension and web storage must be enabled"
代码:
loginGoogle() {
var provider = new firebase.auth.GoogleAuthProvider();
provider.addScope('profile');
provider.addScope('email');
firebase.auth().signInWithPopup(provider).then(function(result) {
var token = result.credential.accessToken;
var user = result.user;
return true;
}).catch(function(error) {
alert(error.code + '
' +
error.message + '
' +
error.email + '
' +
error.credential);
return false;
});
}
推荐答案
signInWithPopup
在 react-native 中不受支持.您将需要使用第三方 OAuth 库来获取 OAuth ID 令牌或访问令牌,然后使用 Firebase 登录:
signInWithPopup
is not supported in react-native. You will need to use a third party OAuth library to get the OAuth ID token or access token and then sign in with Firebase:
const cred = firebase.auth.GoogleAuthProvider.credential(googleIdToken, googleAccessToken);
firebase.auth().signInWithCredential(cred)
.then((result) => {
// User signed in.
})
.catch((error) => {
// Error occurred.
});
相关文章