skip to Main Content

I want to add some extra features after new user login with a google login in Flutter.so I need to know if a user is new or not . if the user is new then I want to add some user information. other wise navigate to another page.

So how can I check If the User is new or not?

2

Answers


  1. The User object has a metadata property, which has two properties: creationTime and lastSignInTime. When those are no more than a few milliseconds apart, the user was just created. If they’re further apart, the user was created in a previous session.

    Login or Signup to reply.
  2. FirebaseAuth User contains this data in metadata prop. I used the following chunk of code. You can change the number of seconds if you want.

    bool isNewUser(User user) {
      DateTime now = DateTime.now();
      DateTime cTime = user.metadata.creationTime;
      int longAgo = 15; // to check account creation under last 15 seconds
      return now.difference(cTime).inSeconds > longAgo;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search