[英]How can I login to Google with React Native and Firebase without using a popup?
As I said, I want to login to my Google Account without having to create a popup, I mean keeping that Login Form with those inputs so the screen on the emulator won't be so empty.正如我所说,我想登录到我的 Google 帐户而不必创建弹出窗口,我的意思是让登录表单与这些输入保持一致,这样模拟器上的屏幕就不会那么空了。 (sorry for the image looking like that, I do not know how to edit it in here.)
(抱歉图片看起来像这样,我不知道如何在这里编辑它。)
I will copy and paste the code for the Firebase login:我将复制并粘贴 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));
})
}
But at the moment it is logging in with Email and Password and not with google.但目前它正在使用 Email 和密码而不是谷歌登录。
I am trying to fetch the name of the user so that is why I want to login with google.我正在尝试获取用户的名称,这就是我想使用 google 登录的原因。
This is a React part I did with Google Authentication.这是我使用 Google Authentication 完成的 React 部分。 It's not tailored to your code but I thought it might help you get where you want to go!
它不是为您的代码量身定制的,但我认为它可能会帮助您到达您想去的地方!
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>;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.