Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用React Native和Firebase登录Google而不使用弹出窗口?_Javascript_Firebase_React Native_Firebase Authentication - Fatal编程技术网

Javascript 如何使用React Native和Firebase登录Google而不使用弹出窗口?

Javascript 如何使用React Native和Firebase登录Google而不使用弹出窗口?,javascript,firebase,react-native,firebase-authentication,Javascript,Firebase,React Native,Firebase Authentication,正如我所说的,我想登录到我的Google帐户,而不必创建弹出窗口,我的意思是保留那些输入的登录表单,这样模拟器上的屏幕就不会那么空。(很抱歉图像看起来像这样,我不知道如何在这里编辑它。) 我将复制并粘贴Firebase登录的代码: onButtonPress() { const {email, password} = this.state; this.setState({ error: '', loading: true }); firebase.auth().s

正如我所说的,我想登录到我的Google帐户,而不必创建弹出窗口,我的意思是保留那些输入的登录表单,这样模拟器上的屏幕就不会那么空。(很抱歉图像看起来像这样,我不知道如何在这里编辑它。)

我将复制并粘贴Firebase登录的代码:

  onButtonPress() {
    const {email, password} = this.state;

    this.setState({ error: '', loading: true });

    firebase.auth().signInWithEmailAndPassword(email, password)
    .then(this.onLoginSuccess.bind(this))
    .catch(() => {
      firebase.auth().createUserWithEmailAndPassword(email, password)
        .then(this.onLoginSuccess.bind(this))
        .catch(this.onLoginFail.bind(this));
  })
}
但目前它是用电子邮件和密码登录的,而不是谷歌


我正在尝试获取用户的姓名,这就是我想使用google登录的原因。

这是我使用google身份验证的一部分。它不是根据您的代码定制的,但我认为它可能会帮助您达到您想要的目的

class GoogleAuth extends React.Component {
  componentDidMount() {
    window.gapi.load("client:auth2", () => {
      window.gapi.client
        .init({
          clientId:
            "65397550643-g040rl648ka1p4d0h0t58crsa5v8ni1a.apps.googleusercontent.com",
          scope: "email"
        })
        .then(() => {
          this.auth = window.gapi.auth2.getAuthInstance();
          this.onAuthChange(this.auth.isSignedIn.get());
          this.auth.isSignedIn.listen(this.onAuthChange);
        });
    });
  }

  onAuthChange = isSignedIn => {
    if (isSignedIn) {
      this.props.signIn(this.auth.currentUser.get().getId());
    } else {
      this.props.signOut();
    }
  };

  onSignInClick = () => {
    this.auth.signIn();
  };

  onSignOutClick = () => {
    this.auth.signOut();
  };

  renderAuthButton = () => {
    if (this.props.isSignedIn === null) {
      return null;
    } else if (this.props.isSignedIn) {
      return (
        <button className="ui red google button" onClick={this.onSignOutClick}>
          <i className="google icon" />
          Sign Out
        </button>
      );
    } else {
      return (
        <button className="ui green google button" onClick={this.onSignInClick}>
          <i className="google icon" />
          Sign in with Google
        </button>
      );
    }
  };

  render() {
    return <div className="item">{this.renderAuthButton()}</div>;
  }
}
class-GoogleAuth扩展了React.Component{
componentDidMount(){
load(“客户端:auth2”,()=>{
window.gapi.client
.init({
客户ID:
“65397550643-g040rl648ka1p4d0h0t58crsa5v8ni1a.apps.googleusercontent.com”,
范围:“电子邮件”
})
.然后(()=>{
this.auth=window.gapi.auth2.getAuthInstance();
this.onAuthChange(this.auth.isSignedIn.get());
this.auth.isSignedIn.listen(this.onAuthChange);
});
});
}
onAuthChange=isSignedIn=>{
如果(伊西涅丁){
this.props.sign(this.auth.currentUser.get().getId());
}否则{
this.props.signOut();
}
};
onSignInClick=()=>{
this.auth.sign();
};
onSignOutClick=()=>{
this.auth.signOut();
};
renderAuthButton=()=>{
if(this.props.isSignedIn==null){
返回null;
}else if(this.props.isSignedIn){
返回(
退出
);
}否则{
返回(
使用谷歌登录
);
}
};
render(){
返回{this.renderAuthButton()};
}
}