Files
TravelMate/lib/services/auth_service.dart
Dayron ec0bc59a70 feat: Integrate Firebase Authentication and Firestore
- Added Firebase configuration to Android and iOS projects.
- Created `google-services.json` and `GoogleService-Info.plist` for Firebase setup.
- Implemented `AuthService` for handling user authentication with Firebase.
- Updated `UserProvider` to manage user data with Firestore.
- Refactored `ProfileContent`, `LoginPage`, and `SignUpPage` to use the new authentication service.
- Removed the old `UserService` and replaced it with Firestore-based user management.
- Added Firebase options in `firebase_options.dart` for platform-specific configurations.
- Updated dependencies in `pubspec.yaml` for Firebase packages.
2025-10-06 18:57:30 +02:00

68 lines
1.8 KiB
Dart

import 'package:firebase_auth/firebase_auth.dart';
class AuthService {
final FirebaseAuth firebaseAuth = FirebaseAuth.instance;
User? get currentUser => firebaseAuth.currentUser;
Stream<User?> get authStateChanges => firebaseAuth.authStateChanges();
Future<UserCredential> signIn({
required String email,
required String password
}) async {
return await firebaseAuth.signInWithEmailAndPassword(
email: email, password: password);
}
Future<UserCredential> createAccount({
required String email,
required String password
}) async {
return await firebaseAuth.createUserWithEmailAndPassword(
email: email, password: password);
}
Future<void> signOut() async {
await firebaseAuth.signOut();
}
Future<void> resetPassword(String email) async {
await firebaseAuth.sendPasswordResetEmail(email: email);
}
Future<void> updateDisplayName({
required String displayName,
}) async {
await currentUser!.updateDisplayName(displayName);
}
Future<void> deleteAccount({
required String password,
required String email,
}) async {
// Re-authenticate the user
AuthCredential credential =
EmailAuthProvider.credential(email: email, password: password);
await currentUser!.reauthenticateWithCredential(credential);
// Delete the user
await currentUser!.delete();
await firebaseAuth.signOut();
}
Future<void> resetPasswordFromCurrentPassword({
required String currentPassword,
required String newPassword,
required String email,
}) async {
// Re-authenticate the user
AuthCredential credential =
EmailAuthProvider.credential(email: email, password: currentPassword);
await currentUser!.reauthenticateWithCredential(credential);
// Update the password
await currentUser!.updatePassword(newPassword);
}
}