Skip to content

Instantly share code, notes, and snippets.

@praharshbhatt
Created December 4, 2019 13:03
Show Gist options
  • Save praharshbhatt/1927f5a84ab358918b14246b243d96e9 to your computer and use it in GitHub Desktop.
Save praharshbhatt/1927f5a84ab358918b14246b243d96e9 to your computer and use it in GitHub Desktop.
Firebase Authentication Functions for Flutter
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