AdditionalUserInfo is a method of the AuthResult
class. If you want to check if the user is logging in for the first time then you can use the value of additionalUserInfo.isNewUser
. The following code logs in a user using Google Auth.
Future<FirebaseUser> _signIn() async {
try {
GoogleSignInAccount googleSignInAccount = await googleSignIn.signIn();
GoogleSignInAuthentication gSA = await googleSignInAccount.authentication;
final AuthCredential credential = GoogleAuthProvider.getCredential(
accessToken: gSA.accessToken,
idToken: gSA.idToken,
);
AuthResult authResult = await _auth.signInWithCredential(credential);
if (authResult.additionalUserInfo.isNewUser) {
//User logging in for the first time
// Redirect user to tutorial
}
else {
//User has already logged in before.
//Show user profile
}
} catch (e) {
print(e.message);
}}
Edit: Since the question was meant for Facebook Login I am adding that code as well. The code below uses flutter_facebook_login
and firebase_auth
packages.
Future<FirebaseUser> _facebookAuthHandler() async {
final result = await facebookLogin.logInWithReadPermissions(['email']);
final AuthCredential credential = FacebookAuthProvider.getCredential(accessToken: result.accessToken.token);
AuthResult authResult = await _auth.signInWithCredential(credential);
if (authResult.additionalUserInfo.isNewUser) {
//TODO User logging in for the first time. Redirect to Pages.SignUp Page
}
else {
//TODO User has already logged in before. Redirect to Home Page
}
}