fayaz07 / flutter_firebase

Implementing features of firebase with flutter
92 stars 67 forks source link

is it possibile to add methods for checking if a user auth with phone already exists or is a new user? #4

Closed thewizard1983 closed 4 years ago

thewizard1983 commented 4 years ago

I would like to create two different screens:

Is there the possibility to know is a user exists with flutter firebase library?

fayaz07 commented 4 years ago

I don't think firebase will give you information about whether the logged in user is new or existing. But you can do one thing, checkout the snippet below and consider your user as new one or existing one. I will keep this issue open, so that if anyone else need this they will use this snippet

FirebaseAuth.instance.currentUser().then((FirebaseUser user){
  Duration duration = user.metadata.creationTime.difference(DateTime.now());

  if(duration.inMinutes < 10){

     // Consider as new user       

  }
});
Pratiknarola commented 4 years ago

why would you want 2 different screens, I mean if the user is new then the user will enter the mobile number and then register with OTP and if the user is already registered then user will log in using OTP. why would you need different screens?

thewizard1983 commented 4 years ago

The first time, I need to ask also other data for user registration, not only the telephone number. The second time they login, I need only the telephone.

Leisser commented 4 years ago

Firebase always gives the user the same "ID" its up-to you to store this id and keep referring to it for any operation. Hope that helps

prudhvir3ddy commented 4 years ago

closing this issue, feel free to re-open for more questions