Expo: “auth/operation-not-supported-in-this-enviroment”

断了今生、忘了曾经 提交于 2020-11-29 08:56:26

问题


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. 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"

Code:

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;
    });
}

回答1:


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.
  });


来源:https://stackoverflow.com/questions/49966086/expo-auth-operation-not-supported-in-this-enviroment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!