firebase.auth().signInWithRedirect(provider);
firebase.auth().getRedirectResult().then(function (result) {
if (result.credential) {
// This gives you a Google Access Token.
var token = result.credential.accessToken;
}
var user = result.user;
}).catch(function (error) {
// Handle Errors here.
console.log(error)
// ...
});
// Start a sign in process for an unauthenticated user.
firebase.auth().onAuthStateChanged(user => {
if (user) {
$state.go('home');
}
})
I am trying to have Google Sign-in, but it always redirects me back to my login page and then after a some time it redirects to home page. After I click the sign in button, it redirects to the Google auth and returns back to the login page. How can this be avoided?
You are always calling signInWithRedirect regardless of the auth state. You should call that when you know the user is not signed in. You can do something like this:
firebase.auth().getRedirectResult().then(function (result) {
if (!user) {
// User not logged in, start login.
firebase.auth().signInWithRedirect(provider);
} else {
// user logged in, go to home page.
$state.go('home');
}
}).catch(function (error) {
// Handle Errors here.
console.log(error)
// ...
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With