Skip to content

Instantly share code, notes, and snippets.

@felangel
Created August 4, 2019 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felangel/7c7fa06f586113e9aa031e329afc6984 to your computer and use it in GitHub Desktop.
Save felangel/7c7fa06f586113e9aa031e329afc6984 to your computer and use it in GitHub Desktop.
[flutter_firestore_todos] firebase user repository
import 'package:firebase_auth/firebase_auth.dart';
import 'package:user_repository/user_repository.dart';
class FirebaseUserRepository implements UserRepository {
final FirebaseAuth _firebaseAuth;
FirebaseUserRepository({FirebaseAuth firebaseAuth})
: _firebaseAuth = firebaseAuth ?? FirebaseAuth.instance;
Future<bool> isAuthenticated() async {
final currentUser = await _firebaseAuth.currentUser();
return currentUser != null;
}
Future<void> authenticate() {
return _firebaseAuth.signInAnonymously();
}
Future<String> getUserId() async {
return (await _firebaseAuth.currentUser()).uid;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment