Created
December 4, 2019 13:03
-
-
Save praharshbhatt/1927f5a84ab358918b14246b243d96e9 to your computer and use it in GitHub Desktop.
Firebase Authentication Functions for Flutter
This file contains 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
import 'package:google_sign_in/google_sign_in.dart'; | |
import 'package:firebase_auth/firebase_auth.dart'; | |
//This contains actual user information | |
MobFirebaseAuth.FirebaseUser firebaseUser; | |
//This is the main Firebase auth object | |
MobFirebaseAuth.FirebaseAuth mobAuth = MobFirebaseAuth.FirebaseAuth.instance; | |
// For google sign in | |
final GoogleSignIn objGoogleSignIn = GoogleSignIn(); | |
//Log in using google | |
Future<FirebaseUser> googleSignIn() async { | |
//For mobile | |
// Step 1 | |
GoogleSignInAccount googleUser = await objGoogleSignIn.signIn(); | |
// Step 2 | |
GoogleSignInAuthentication googleAuth = await googleUser.authentication; | |
final AuthCredential credential = GoogleAuthProvider.getCredential( | |
accessToken: googleAuth.accessToken, | |
idToken: googleAuth.idToken, | |
); | |
AuthResult _res = await mobAuth.signInWithCredential(credential); | |
firebaseUser = _res.user; | |
return firebaseUser; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment