Created
August 4, 2019 18:44
-
-
Save felangel/7c7fa06f586113e9aa031e329afc6984 to your computer and use it in GitHub Desktop.
[flutter_firestore_todos] firebase user repository
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: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