fix(auth): connexion admin - token snake_case, routes GoRouter, profil (Closes #84)
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
480f4a9396
commit
18af5c9034
@ -19,6 +19,8 @@ import '../screens/auth/am_register_step2_screen.dart';
|
|||||||
import '../screens/auth/am_register_step3_screen.dart';
|
import '../screens/auth/am_register_step3_screen.dart';
|
||||||
import '../screens/auth/am_register_step4_screen.dart';
|
import '../screens/auth/am_register_step4_screen.dart';
|
||||||
import '../screens/home/home_screen.dart';
|
import '../screens/home/home_screen.dart';
|
||||||
|
import '../screens/administrateurs/admin_dashboardScreen.dart';
|
||||||
|
import '../screens/home/parent_screen/ParentDashboardScreen.dart';
|
||||||
import '../screens/unknown_screen.dart';
|
import '../screens/unknown_screen.dart';
|
||||||
|
|
||||||
// --- Provider Instances ---
|
// --- Provider Instances ---
|
||||||
@ -47,6 +49,18 @@ class AppRouter {
|
|||||||
path: '/home',
|
path: '/home',
|
||||||
builder: (BuildContext context, GoRouterState state) => const HomeScreen(),
|
builder: (BuildContext context, GoRouterState state) => const HomeScreen(),
|
||||||
),
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: '/admin-dashboard',
|
||||||
|
builder: (BuildContext context, GoRouterState state) => const AdminDashboardScreen(),
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: '/parent-dashboard',
|
||||||
|
builder: (BuildContext context, GoRouterState state) => const ParentDashboardScreen(),
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: '/am-dashboard',
|
||||||
|
builder: (BuildContext context, GoRouterState state) => const HomeScreen(),
|
||||||
|
),
|
||||||
|
|
||||||
// --- Parent Registration Flow ---
|
// --- Parent Registration Flow ---
|
||||||
ShellRoute(
|
ShellRoute(
|
||||||
|
|||||||
@ -20,8 +20,12 @@ class AppUser {
|
|||||||
id: json['id'] as String,
|
id: json['id'] as String,
|
||||||
email: json['email'] as String,
|
email: json['email'] as String,
|
||||||
role: json['role'] as String,
|
role: json['role'] as String,
|
||||||
createdAt: DateTime.parse(json['createdAt'] as String),
|
createdAt: json['createdAt'] != null
|
||||||
updatedAt: DateTime.parse(json['updatedAt'] as String),
|
? DateTime.parse(json['createdAt'] as String)
|
||||||
|
: DateTime.now(),
|
||||||
|
updatedAt: json['updatedAt'] != null
|
||||||
|
? DateTime.parse(json['updatedAt'] as String)
|
||||||
|
: DateTime.now(),
|
||||||
changementMdpObligatoire: json['changement_mdp_obligatoire'] as bool? ?? false,
|
changementMdpObligatoire: json['changement_mdp_obligatoire'] as bool? ?? false,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -116,21 +116,23 @@ class _LoginPageState extends State<LoginScreen> with WidgetsBindingObserver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Redirige l'utilisateur selon son rôle
|
/// Redirige l'utilisateur selon son rôle (GoRouter : context.go).
|
||||||
void _redirectUserByRole(String role) {
|
void _redirectUserByRole(String role) {
|
||||||
|
setState(() => _isLoading = false);
|
||||||
switch (role.toLowerCase()) {
|
switch (role.toLowerCase()) {
|
||||||
case 'super_admin':
|
case 'super_admin':
|
||||||
|
case 'administrateur':
|
||||||
case 'gestionnaire':
|
case 'gestionnaire':
|
||||||
Navigator.pushReplacementNamed(context, '/admin-dashboard');
|
context.go('/admin-dashboard');
|
||||||
break;
|
break;
|
||||||
case 'parent':
|
case 'parent':
|
||||||
Navigator.pushReplacementNamed(context, '/parent-dashboard');
|
context.go('/parent-dashboard');
|
||||||
break;
|
break;
|
||||||
case 'assistante_maternelle':
|
case 'assistante_maternelle':
|
||||||
Navigator.pushReplacementNamed(context, '/am-dashboard');
|
context.go('/am-dashboard');
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Navigator.pushReplacementNamed(context, '/home');
|
context.go('/home');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -23,13 +23,15 @@ class AuthService {
|
|||||||
|
|
||||||
if (response.statusCode == 200 || response.statusCode == 201) {
|
if (response.statusCode == 200 || response.statusCode == 201) {
|
||||||
final data = jsonDecode(response.body);
|
final data = jsonDecode(response.body);
|
||||||
|
// API renvoie access_token / refresh_token (snake_case)
|
||||||
|
final accessToken = data['access_token'] as String? ?? data['accessToken'] as String?;
|
||||||
|
final refreshToken = data['refresh_token'] as String? ?? data['refreshToken'] as String?;
|
||||||
|
if (accessToken == null) throw Exception('Token absent dans la réponse serveur');
|
||||||
|
|
||||||
// Stocker les tokens
|
await TokenService.saveToken(accessToken);
|
||||||
await TokenService.saveToken(data['accessToken']);
|
await TokenService.saveRefreshToken(refreshToken ?? '');
|
||||||
await TokenService.saveRefreshToken(data['refreshToken']);
|
|
||||||
|
|
||||||
// Récupérer le profil utilisateur pour avoir toutes les infos
|
final user = await _fetchUserProfile(accessToken);
|
||||||
final user = await _fetchUserProfile(data['accessToken']);
|
|
||||||
|
|
||||||
// Stocker l'utilisateur en cache
|
// Stocker l'utilisateur en cache
|
||||||
await _saveCurrentUser(user);
|
await _saveCurrentUser(user);
|
||||||
@ -80,8 +82,9 @@ class AuthService {
|
|||||||
Uri.parse('${ApiConfig.baseUrl}${ApiConfig.changePasswordRequired}'),
|
Uri.parse('${ApiConfig.baseUrl}${ApiConfig.changePasswordRequired}'),
|
||||||
headers: ApiConfig.authHeaders(token),
|
headers: ApiConfig.authHeaders(token),
|
||||||
body: jsonEncode({
|
body: jsonEncode({
|
||||||
'currentPassword': currentPassword,
|
'mot_de_passe_actuel': currentPassword,
|
||||||
'newPassword': newPassword,
|
'nouveau_mot_de_passe': newPassword,
|
||||||
|
'confirmation_mot_de_passe': newPassword,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user