Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.
});
like image 615
Dinesh Avatar asked May 09 '20 16:05

Dinesh


People also ask

Which method will you call to logout a user from Firebase?

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 authentication work Firebase?

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.


Video Answer


1 Answers

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.

like image 174
Frank van Puffelen Avatar answered Nov 16 '22 02:11

Frank van Puffelen