Created
March 8, 2020 18:32
-
-
Save prasadsunny1/a65047f11d4c345a79c3bfc1f5246b44 to your computer and use it in GitHub Desktop.
Google signin using flirebase in flutter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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