-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #146 from Manzee1609/GoogleAuth
Added google signin(#27)
- Loading branch information
Showing
4 changed files
with
63 additions
and
5 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import 'package:firebase_core/firebase_core.dart'; | ||
import 'package:google_sign_in/google_sign_in.dart'; | ||
import 'package:firebase_auth/firebase_auth.dart'; | ||
|
||
final FirebaseAuth _auth = FirebaseAuth.instance; | ||
final GoogleSignIn googleSignIn = GoogleSignIn(); | ||
|
||
|
||
Future<String> signInWithGoogle() async { | ||
await Firebase.initializeApp(); | ||
|
||
final GoogleSignInAccount googleSignInAccount = await googleSignIn.signIn(); | ||
final GoogleSignInAuthentication googleSignInAuthentication = await googleSignInAccount.authentication; | ||
|
||
final AuthCredential credential = GoogleAuthProvider.credential( | ||
accessToken: googleSignInAuthentication.accessToken, | ||
idToken: googleSignInAuthentication.idToken, | ||
); | ||
|
||
final UserCredential authResult = await _auth.signInWithCredential(credential); | ||
final User user = authResult.user; | ||
assert(!user.isAnonymous); | ||
|
||
final User currentUser = _auth.currentUser; | ||
assert(user.uid == currentUser.uid); | ||
|
||
return '$user'; | ||
} | ||
|
||
Future<void> signOutGoogle() async { | ||
await googleSignIn.signOut(); | ||
} |
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
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
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