博览会:“此环境不支持身份验证/操作" [英] Expo: "auth/operation-not-supported-in-this-enviroment"
问题描述
我开发了一个本机(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:
此环境不支持身份验证/操作.在此应用程序运行的环境中不支持此操作." 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 + '\n' +
error.message + '\n' +
error.email + '\n' +
error.credential);
return false;
});
}
react-native不支持
推荐答案
signInWithPopup
.您将需要使用第三方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.
});
这篇关于博览会:“此环境不支持身份验证/操作"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!