Add routes navigation login and admin dashboard

This commit is contained in:
Hanim
2025-09-12 15:24:52 +02:00
parent 9fd6cb7b76
commit e2e38076aa
11 changed files with 821 additions and 90 deletions
+13 -2
View File
@@ -1,6 +1,6 @@
class ApiConfig {
// static const String baseUrl = 'https://ynov.ptits-pas.fr/api/v1';
static const String baseUrl = 'http://localhost:3000/api/v1';
// static const String baseUrl = 'http://localhost:3000/api/v1/';
static const String baseUrl = 'https://ynov.ptits-pas.fr/api/v1';
// Auth endpoints
static const String login = '/auth/login';
@@ -18,4 +18,15 @@ class ApiConfig {
static const String contracts = '/contracts';
static const String conversations = '/conversations';
static const String notifications = '/notifications';
// Headers
static Map<String, String> get headers => {
'Content-Type': 'application/json',
'Accept': 'application/json',
};
static Map<String, String> authHeaders(String token) => {
...headers,
'Authorization': 'Bearer $token',
};
}
@@ -0,0 +1,72 @@
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:shared_preferences/shared_preferences.dart';
class TokenService {
static const _storage = FlutterSecureStorage();
static const _tokenKey = 'access_token';
static const String _refreshTokenKey = 'refresh_token';
static const _roleKey = 'user_role';
// Stockage du token
static Future<void> saveToken(String token) async {
final prefs = await SharedPreferences.getInstance();
await prefs.setString(_tokenKey, token);
}
// Stockage du refresh token
static Future<void> saveRefreshToken(String refreshToken) async {
final prefs = await SharedPreferences.getInstance();
await prefs.setString(_refreshTokenKey, refreshToken);
}
// Stockage du rôle
static Future<void> saveRole(String role) async {
final prefs = await SharedPreferences.getInstance();
await prefs.setString(_roleKey, role);
}
// Récupération du token
static Future<String?> getToken() async {
final prefs = await SharedPreferences.getInstance();
return prefs.getString(_tokenKey);
}
// Récupération du refresh token
static Future<String?> getRefreshToken() async {
final prefs = await SharedPreferences.getInstance();
return prefs.getString(_refreshTokenKey);
}
// Récupération du rôle
static Future<String?> getRole() async {
final prefs = await SharedPreferences.getInstance();
return prefs.getString(_roleKey);
}
// Suppression du token
static Future<void> deleteToken() async {
final prefs = await SharedPreferences.getInstance();
await prefs.remove(_tokenKey);
}
// Suppression du refresh token
static Future<void> deleteRefreshToken() async {
final prefs = await SharedPreferences.getInstance();
await prefs.remove(_refreshTokenKey);
}
// Suppression du rôle
static Future<void> deleteRole() async {
final prefs = await SharedPreferences.getInstance();
await prefs.remove(_roleKey);
}
// Nettoyage complet
static Future<void> clearAll() async {
final prefs = await SharedPreferences.getInstance();
await prefs.remove(_tokenKey);
await prefs.remove(_refreshTokenKey);
await prefs.remove(_roleKey);
}
}