Skip to content

Instantly share code, notes, and snippets.

@prasadsunny1
Created March 8, 2020 18:32
Show Gist options
  • Save prasadsunny1/a65047f11d4c345a79c3bfc1f5246b44 to your computer and use it in GitHub Desktop.
Save prasadsunny1/a65047f11d4c345a79c3bfc1f5246b44 to your computer and use it in GitHub Desktop.
Google signin using flirebase in flutter
Future<User> signInWithGoogle() async {
final googleSignIn = GoogleSignIn();
final googleAccount = await googleSignIn.signIn();
if (googleAccount != null) {
final googleAuth = await googleAccount.authentication;
if (googleAuth.accessToken != null && googleAuth.idToken != null) {
final authResult = await _firebaseAuth.signInWithCredential(
GoogleAuthProvider.getCredential(
idToken: googleAuth.idToken,
accessToken: googleAuth.accessToken,
),
);
return _userFromFirebase(authResult.user);
} else {
throw PlatformException(
code: 'ERROR_MISSING_GOOGLE_AUTH_TOKEN',
message: 'Missing Google Auth Token',
);
}
} else {
throw PlatformException(
code: 'ERROR_ABORTED_BY_USER',
message: 'Sign in aborted by user',
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment