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.
});
Signing out If you'd like to sign the user out of their current authentication state, call the signOut method: import auth from '@react-native-firebase/auth'; auth() . signOut() .
How does it work? To sign a user into your app, you first get authentication credentials from the user. These credentials can be the user's email address and password, or an OAuth token from a federated identity provider. Then, you pass these credentials to the Firebase Authentication SDK.
The UserCredential
object you get as result
has an additionalUserInfo
member that has an isNewUser
property.
So result.additionalUserInfo.isNewUser
will be true the first time the user signs in, and false afterwards.
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