Created
July 19, 2018 07:33
-
-
Save deepak-gehlot/2b255b99cc85ca47b429a7827d10f322 to your computer and use it in GitHub Desktop.
Firebase Authentication : Register user, Login user, Login with google
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:firebase_auth/firebase_auth.dart'; | |
import 'package:google_sign_in/google_sign_in.dart'; | |
import 'dart:async'; | |
class PersonData { | |
String name = ''; | |
String phoneNumber = ''; | |
String email = ''; | |
String password = ''; | |
} | |
class UserAuth { | |
String statusMsg = "Account Created Successfully"; | |
//To create new User | |
Future<FirebaseUser> createUser(PersonData userData) async { | |
FirebaseAuth firebaseAuth = FirebaseAuth.instance; | |
return firebaseAuth.createUserWithEmailAndPassword( | |
email: userData.email, password: userData.password); | |
} | |
//To verify new User | |
Future<FirebaseUser> verifyUser(PersonData userData) { | |
FirebaseAuth firebaseAuth = FirebaseAuth.instance; | |
return firebaseAuth.signInWithEmailAndPassword( | |
email: userData.email, password: userData.password); | |
} | |
/// sign our user | |
void signOut() { | |
FirebaseAuth firebaseAuth = FirebaseAuth.instance; | |
firebaseAuth.signOut(); | |
} | |
/// sign in with google | |
Future<FirebaseUser> signInWithGoogle() async { | |
FirebaseAuth firebaseAuth = FirebaseAuth.instance; | |
final GoogleSignIn _googleSignIn = new GoogleSignIn(); | |
GoogleSignInAccount googleUser = await _googleSignIn.signIn(); | |
GoogleSignInAuthentication googleAuth = await googleUser.authentication; | |
FirebaseUser user = await firebaseAuth.signInWithGoogle( | |
accessToken: googleAuth.accessToken, | |
idToken: googleAuth.idToken, | |
); | |
return user; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment