feat: Implement Firebase push notifications with support for flavor-specific configurations.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:real_estate_mobile/core/network/api_client.dart';
|
||||
import 'package:real_estate_mobile/core/network/api_exceptions.dart';
|
||||
import 'package:real_estate_mobile/core/services/push_notification_service.dart';
|
||||
import 'package:real_estate_mobile/core/storage/secure_storage.dart';
|
||||
import 'package:real_estate_mobile/features/auth/data/auth_repository.dart';
|
||||
import 'package:real_estate_mobile/features/auth/data/models/register_request.dart';
|
||||
@@ -76,6 +77,8 @@ class AuthNotifier extends StateNotifier<AuthState> {
|
||||
status: AuthStatus.authenticated,
|
||||
user: user,
|
||||
);
|
||||
// Register for push notifications after auth confirmed
|
||||
_initPushNotifications();
|
||||
} catch (_) {
|
||||
// Token is invalid/expired — clear and show login
|
||||
await SecureStorage.clearTokens();
|
||||
@@ -85,6 +88,8 @@ class AuthNotifier extends StateNotifier<AuthState> {
|
||||
|
||||
Future<void> logout() async {
|
||||
state = state.copyWith(status: AuthStatus.loading);
|
||||
// Unregister FCM token before clearing auth
|
||||
await PushNotificationService().unregister();
|
||||
await _repository.logout();
|
||||
state = const AuthState();
|
||||
}
|
||||
@@ -117,6 +122,7 @@ class AuthNotifier extends StateNotifier<AuthState> {
|
||||
status: AuthStatus.authenticated,
|
||||
user: result['user'] as UserModel,
|
||||
);
|
||||
_initPushNotifications();
|
||||
} on ApiException catch (e) {
|
||||
state = state.copyWith(
|
||||
status: AuthStatus.error,
|
||||
@@ -166,6 +172,7 @@ class AuthNotifier extends StateNotifier<AuthState> {
|
||||
user: user,
|
||||
registeredEmail: email,
|
||||
);
|
||||
_initPushNotifications();
|
||||
} on ApiException catch (e) {
|
||||
state = state.copyWith(
|
||||
status: AuthStatus.error,
|
||||
@@ -182,6 +189,11 @@ class AuthNotifier extends StateNotifier<AuthState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _initPushNotifications() {
|
||||
final push = PushNotificationService();
|
||||
push.initialize().then((_) => push.registerAfterLogin());
|
||||
}
|
||||
|
||||
void reset() {
|
||||
state = const AuthState();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user