35 lines
904 B
Dart
35 lines
904 B
Dart
import 'package:firebase_auth/firebase_auth.dart';
|
|
import 'package:cloud_firestore/cloud_firestore.dart';
|
|
|
|
class AuthService {
|
|
final FirebaseAuth _auth = FirebaseAuth.instance;
|
|
final FirebaseFirestore _firestore = FirebaseFirestore.instance;
|
|
|
|
Future<Map<String, dynamic>?> login({
|
|
required String email,
|
|
required String password,
|
|
}) async {
|
|
try {
|
|
UserCredential userCredential =
|
|
await _auth.signInWithEmailAndPassword(
|
|
email: email,
|
|
password: password,
|
|
);
|
|
|
|
final uid = userCredential.user!.uid;
|
|
|
|
// 🔥 ambil data dari firestore
|
|
DocumentSnapshot userDoc =
|
|
await _firestore.collection('users').doc(uid).get();
|
|
|
|
return userDoc.data() as Map<String, dynamic>?;
|
|
|
|
} on FirebaseAuthException catch (e) {
|
|
throw Exception(e.message);
|
|
}
|
|
}
|
|
|
|
Future<void> logout() async {
|
|
await _auth.signOut();
|
|
}
|
|
} |