-
-
Save ijoschek/2af14c3eb123278d792968c0020d7658 to your computer and use it in GitHub Desktop.
flutter_auth_tut
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 'dart:async'; | |
import 'package:firebase_auth/firebase_auth.dart'; | |
import 'package:google_sign_in/google_sign_in.dart'; | |
final FirebaseAuth _auth = FirebaseAuth.instance; | |
final GoogleSignIn _googleSignIn = GoogleSignIn(); | |
Future<FirebaseUser> loginWithGoogle() async { | |
GoogleSignInAccount currentUser = _googleSignIn.currentUser; | |
if (currentUser == null) { | |
currentUser = await _googleSignIn.signInSilently(); | |
} | |
if (currentUser == null) { | |
currentUser = await _googleSignIn.signIn(); | |
if (currentUser == null) { | |
throw('Login Canceled'); | |
} | |
} | |
final GoogleSignInAuthentication auth = await currentUser.authentication; | |
final FirebaseUser user = | |
await _auth.signInWithCredential(GoogleAuthProvider.getCredential( | |
idToken: gAuth.idToken, | |
accessToken: gAuth.accessToken, | |
)); | |
assert(user != null); | |
assert(!user.isAnonymous); | |
assert(await user.getIdToken() != null); | |
return user; | |
} | |
//... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment