博览会:“此环境中不支持身份验证/操作”

AL1*_*e1T 5 javascript firebase react-native firebase-authentication expo

我开发了一个react-native(expo)移动应用程序并尝试使用google帐户登录firebase,但出现错误:

“auth/operation-not-supported-in-this-enviroment。此应用程序运行的环境不支持此操作。“location.protocol”必须是 http、https 或 chrome-extension,并且必须启用 Web 存储”

代码:

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;
    });
}
Run Code Online (Sandbox Code Playgroud)

boj*_*eil 3

signInWithPopupReact-Native 不支持。您将需要使用第三方 OAuth 库来获取 OAuth ID 令牌或访问令牌,然后使用 Firebase 登录:

const cred = firebase.auth.GoogleAuthProvider.credential(googleIdToken, googleAccessToken);
firebase.auth().signInWithCredential(cred)
  .then((result) => {
    // User signed in.
  })
  .catch((error) => {
    // Error occurred.
  });
Run Code Online (Sandbox Code Playgroud)