L'authentification Keycloak WebView est maintenant 100% fonctionnelle avec navigation automatique vers le dashboard !

This commit is contained in:
DahoudG
2025-09-19 13:03:09 +00:00
parent 098894bdc1
commit 4ac376b7e7
4 changed files with 53 additions and 31 deletions

View File

@@ -64,11 +64,12 @@ class AuthUserProfileUpdated extends AuthEvent {
/// Événement de callback WebView /// Événement de callback WebView
class AuthWebViewCallback extends AuthEvent { class AuthWebViewCallback extends AuthEvent {
final String callbackUrl; final String callbackUrl;
final User? user;
const AuthWebViewCallback(this.callbackUrl); const AuthWebViewCallback(this.callbackUrl, {this.user});
@override @override
List<Object?> get props => [callbackUrl]; List<Object?> get props => [callbackUrl, user];
} }
// === ÉTATS === // === ÉTATS ===
@@ -254,10 +255,17 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
try { try {
debugPrint('🔄 Traitement callback WebView...'); debugPrint('🔄 Traitement callback WebView...');
// Traiter le callback et récupérer l'utilisateur // Utiliser l'utilisateur fourni ou traiter le callback
final User user = await KeycloakAuthService.handleWebViewCallback(event.callbackUrl); final User user;
if (event.user != null) {
debugPrint('👤 Utilisation des données utilisateur fournies: ${event.user!.fullName}');
user = event.user!;
} else {
debugPrint('🔄 Traitement du callback URL: ${event.callbackUrl}');
user = await KeycloakAuthService.handleWebViewCallback(event.callbackUrl);
}
debugPrint('👤 Utilisateur récupéré: ${user.fullName} (${user.primaryRole.displayName})'); debugPrint('👤 Utilisateur authentifié: ${user.fullName} (${user.primaryRole.displayName})');
// Calculer les permissions effectives // Calculer les permissions effectives
debugPrint('🔐 Calcul des permissions effectives...'); debugPrint('🔐 Calcul des permissions effectives...');
@@ -278,7 +286,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
accessToken: '', // Token géré par KeycloakWebViewAuthService accessToken: '', // Token géré par KeycloakWebViewAuthService
)); ));
debugPrint('🎉 Authentification complète réussie'); debugPrint('🎉 Authentification complète réussie - navigation vers dashboard');
} catch (e, stackTrace) { } catch (e, stackTrace) {
debugPrint('💥 Erreur authentification: $e'); debugPrint('💥 Erreur authentification: $e');

View File

@@ -73,11 +73,16 @@ class _LoginPageState extends State<LoginPage>
builder: (context) => KeycloakWebViewAuthPage( builder: (context) => KeycloakWebViewAuthPage(
onAuthSuccess: (user) { onAuthSuccess: (user) {
debugPrint('✅ Authentification réussie pour: ${user.fullName}'); debugPrint('✅ Authentification réussie pour: ${user.fullName}');
// Notifier le BLoC du succès debugPrint('🔄 Notification du BLoC avec les données utilisateur...');
context.read<AuthBloc>().add(AuthWebViewCallback('success'));
// Fermer la WebView et naviguer vers le dashboard // Notifier le BLoC du succès avec les données utilisateur
context.read<AuthBloc>().add(AuthWebViewCallback(
'success',
user: user,
));
// Fermer la WebView - la navigation sera gérée par le BlocListener
Navigator.of(context).pop(); Navigator.of(context).pop();
Navigator.of(context).pushReplacementNamed('/dashboard');
}, },
onAuthError: (error) { onAuthError: (error) {
debugPrint('❌ Erreur d\'authentification: $error'); debugPrint('❌ Erreur d\'authentification: $error');

View File

@@ -117,13 +117,15 @@ class VisitorDashboard extends StatelessWidget {
children: [ children: [
const Icon(Icons.info_outline, color: Colors.white, size: 30), const Icon(Icons.info_outline, color: Colors.white, size: 30),
const SizedBox(width: SpacingTokens.sm), const SizedBox(width: SpacingTokens.sm),
Text( Expanded(
child: Text(
'Découvrez notre communauté', 'Découvrez notre communauté',
style: TypographyTokens.headlineMedium.copyWith( style: TypographyTokens.headlineMedium.copyWith(
color: Colors.white, color: Colors.white,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
),
], ],
), ),
const SizedBox(height: SpacingTokens.md), const SizedBox(height: SpacingTokens.md),

View File

@@ -74,8 +74,9 @@ class UnionFlowApp extends StatelessWidget {
GlobalCupertinoLocalizations.delegate, GlobalCupertinoLocalizations.delegate,
], ],
// Page d'accueil avec authentification // Configuration des routes
home: BlocBuilder<AuthBloc, AuthState>( routes: {
'/': (context) => BlocBuilder<AuthBloc, AuthState>(
builder: (context, state) { builder: (context, state) {
if (state is AuthLoading) { if (state is AuthLoading) {
return const Scaffold( return const Scaffold(
@@ -90,6 +91,12 @@ class UnionFlowApp extends StatelessWidget {
} }
}, },
), ),
'/dashboard': (context) => const AdaptiveDashboardPage(),
'/login': (context) => const LoginPage(),
},
// Page d'accueil par défaut
initialRoute: '/',
// Builder global pour gérer les erreurs // Builder global pour gérer les erreurs
builder: (context, child) { builder: (context, child) {