Trying to do the notification for all users.

This commit is contained in:
Van Leemput Dayron
2025-12-03 17:32:06 +01:00
parent fd19b88eef
commit a74d76b485
10 changed files with 505 additions and 227 deletions

View File

@@ -25,6 +25,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import '../../repositories/auth_repository.dart';
import 'auth_event.dart';
import 'auth_state.dart';
import '../../services/notification_service.dart';
/// BLoC for managing authentication state and operations.
class AuthBloc extends Bloc<AuthEvent, AuthState> {
@@ -69,6 +70,8 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
);
if (user != null) {
// Save FCM Token on auto-login
await NotificationService().saveTokenToFirestore(user.id!);
emit(AuthAuthenticated(user: user));
} else {
emit(AuthUnauthenticated());
@@ -98,6 +101,8 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
);
if (user != null) {
// Save FCM Token
await NotificationService().saveTokenToFirestore(user.id!);
emit(AuthAuthenticated(user: user));
} else {
emit(const AuthError(message: 'Invalid email or password'));
@@ -127,6 +132,8 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
);
if (user != null) {
// Save FCM Token
await NotificationService().saveTokenToFirestore(user.id!);
emit(AuthAuthenticated(user: user));
} else {
emit(const AuthError(message: 'Failed to create account'));
@@ -150,6 +157,8 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
final user = await _authRepository.signInWithGoogle();
if (user != null) {
// Save FCM Token
await NotificationService().saveTokenToFirestore(user.id!);
emit(AuthAuthenticated(user: user));
} else {
emit(
@@ -224,6 +233,8 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
final user = await _authRepository.signInWithApple();
if (user != null) {
// Save FCM Token
await NotificationService().saveTokenToFirestore(user.id!);
emit(AuthAuthenticated(user: user));
} else {
emit(

View File

@@ -86,9 +86,9 @@ class UserBloc extends Bloc<event.UserEvent, state.UserState> {
// Update FCM token if it changed
if (fcmToken != null && user.fcmToken != fcmToken) {
LoggerService.info('UserBloc - Updating FCM token in Firestore');
await _firestore.collection('users').doc(currentUser.uid).update({
await _firestore.collection('users').doc(currentUser.uid).set({
'fcmToken': fcmToken,
});
}, SetOptions(merge: true));
LoggerService.info('UserBloc - FCM token updated');
} else {
LoggerService.info(