top of page

[Flutter/dart] Determine if the login is first login in firebase_auth


Summary


If you are using the login function with a google account etc. in the app, you may want to determine whether it is the first login. For example, when a user log in for the first time, you can create a database for that user.

This time, I will introduce how to determine the first login when using the google login of firebase_auth.



Method


The version of firebase_auth is 0.18.4.


UserCredential > additionalUserInfo > isNewUser

contains information about whether a user are logged in for the first time. IsNewUser will be true for the first login.

Methods like signInWithCredential(), signInAnonymously() return the instance of UserCredential and you can use it.


//Authenticate user with google account
Future<UserCredential> authGoogleUser(FirebaseAuth auth, 
                            GoogleSignInAccount googleAccount) async{

  GoogleSignInAuthentication _googleAuth=await 
                                          googleAccount.authentication;
  final AuthCredential _credential=GoogleAuthProvider.credential(
      accessToken: _googleAuth.accessToken, idToken: _googleAuth.idToken
  );

  UserCredential cred=await auth.signInWithCredential(_credential);
  user=cred.user;  //User information
  isFirst=cred.additionalUserInfo.isNewUser;   //wheher first login

  return cred;
}


Recent Posts

See All

Comments


category

Let's do our best with our partner:​ ChatReminder

iphone6.5p2.png

It is an application that achieves goals in a chat format with partners.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png

Let's do our best with our partner:​ ChatReminder

納品:iPhone6.5①.png

It is an application that achieves goals in a chat format with partners.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png

Theme diary: Decide the theme and record for each genre

It is a diary application that allows you to post and record with themes and sub-themes for each genre.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png
bottom of page