Created
May 26, 2021 19:35
-
-
Save PeterHdd/cc76a7ff6c0e4c7a8161dd86b69fe26e to your computer and use it in GitHub Desktop.
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
class FirebaseService { | |
final FirebaseAuth _auth = FirebaseAuth.instance; | |
final GoogleSignIn _googleSignIn = GoogleSignIn(); | |
Future<String?> signInwithGoogle() async { | |
try { | |
final GoogleSignInAccount? googleSignInAccount = | |
await _googleSignIn.signIn(); | |
final GoogleSignInAuthentication googleSignInAuthentication = | |
await googleSignInAccount!.authentication; | |
final AuthCredential credential = GoogleAuthProvider.credential( | |
accessToken: googleSignInAuthentication.accessToken, | |
idToken: googleSignInAuthentication.idToken, | |
); | |
await _auth.signInWithCredential(credential); | |
} on FirebaseAuthException catch (e) { | |
print(e.message); | |
throw e; | |
} | |
} | |
Future<void> signOutFromGoogle() async{ | |
await _googleSignIn.signOut(); | |
await _auth.signOut(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment