'How to differentiate signin and signup user in firebase using google auth?
I am using firebase to authenticate user. If new user signin using google/facebook provider, it creates a user and automatically sign in. After user signin, how to differentiate between signIn and signUp?
var provider = new firebase.auth.GoogleAuthProvider();
firebase.auth().signInWithPopup(provider).then(function(result) {
var token = result.credential.accessToken;
var user = result.user;
// if new user i want to redirect to some other page.
// if user already exist, i want to redirect to home page
}).catch(function(error) {
// Handle Errors here.
});
Solution 1:[1]
use getAdditionalUserInfo
var provider = new firebase.auth.GoogleAuthProvider();
firebase
.auth()
.signInWithPopup(provider)
.then(function (result) {
var token = result.credential.accessToken;
var user = result.user;
const additionalUserInfo = getAdditionalUserInfo(userCredential);
if (additionalUserInfo.isNewUser) {
// if new user i want to redirect to some other page.
} else {
// if user already exist, i want to redirect to home page
}
})
.catch(function (error) {
// Handle Errors here.
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
