Skip to content

Instantly share code, notes, and snippets.

@aaronksaunders
Created May 30, 2019 23:46
Show Gist options
  • Save aaronksaunders/bac9ab2048d2c5e3375bb2e218d95d07 to your computer and use it in GitHub Desktop.
Save aaronksaunders/bac9ab2048d2c5e3375bb2e218d95d07 to your computer and use it in GitHub Desktop.
Markdium-Simple Firebase Login Flow in Flutter
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