Created
May 30, 2019 23:46
-
-
Save aaronksaunders/bac9ab2048d2c5e3375bb2e218d95d07 to your computer and use it in GitHub Desktop.
Markdium-Simple Firebase Login Flow in Flutter
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
import 'package:firebase_auth/firebase_auth.dart'; | |
import 'dart:async'; | |
class AuthService { | |
final FirebaseAuth _auth = FirebaseAuth.instance; | |
// return the Future with firebase user if one exists | |
Future get getUser => _auth.currentUser(); | |
// wrapping the firebase calls | |
Future logout() { | |
return FirebaseAuth.instance.signOut(); | |
} | |
// wrapping the firebase calls | |
Future createUser( | |
{String firstName, | |
String lastName, | |
String email, | |
String password}) async { | |
var u = await FirebaseAuth.instance | |
.createUserWithEmailAndPassword(email: email, password: password); | |
UserUpdateInfo info = UserUpdateInfo(); | |
info.displayName = '$firstName $lastName'; | |
return await u.updateProfile(info); | |
} | |
// wrapping the firebase calls | |
Future loginUser({String email, String password}) { | |
return FirebaseAuth.instance | |
.signInWithEmailAndPassword(email: email, password: password); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment