fix(ui): use TokenService to fix 401 Unauthorized when calling absences API
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -2,11 +2,11 @@ import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:p_tits_pas/models/absence_garde.dart';
|
||||
import 'package:p_tits_pas/services/api/api_config.dart';
|
||||
import 'package:p_tits_pas/services/auth_service.dart';
|
||||
import 'package:p_tits_pas/services/api/tokenService.dart';
|
||||
|
||||
class AbsencesGardeService {
|
||||
static Future<List<AbsenceGarde>> getAbsences({String? placementId}) async {
|
||||
final token = await AuthService.getToken();
|
||||
final token = await TokenService.getToken();
|
||||
final headers = token != null ? ApiConfig.authHeaders(token) : ApiConfig.headers;
|
||||
|
||||
final uri = Uri.parse(ApiConfig.baseUrl +
|
||||
@@ -30,7 +30,7 @@ class AbsencesGardeService {
|
||||
required String dateFin,
|
||||
String? motif,
|
||||
}) async {
|
||||
final token = await AuthService.getToken();
|
||||
final token = await TokenService.getToken();
|
||||
final headers = token != null ? ApiConfig.authHeaders(token) : ApiConfig.headers;
|
||||
|
||||
final uri = Uri.parse('${ApiConfig.baseUrl}/absences-garde');
|
||||
@@ -59,7 +59,7 @@ class AbsencesGardeService {
|
||||
String? statut,
|
||||
String? motif,
|
||||
}) async {
|
||||
final token = await AuthService.getToken();
|
||||
final token = await TokenService.getToken();
|
||||
final headers = token != null ? ApiConfig.authHeaders(token) : ApiConfig.headers;
|
||||
|
||||
final uri = Uri.parse('${ApiConfig.baseUrl}/absences-garde/$id');
|
||||
@@ -82,7 +82,7 @@ class AbsencesGardeService {
|
||||
}
|
||||
|
||||
static Future<void> supprimerAbsence(String id) async {
|
||||
final token = await AuthService.getToken();
|
||||
final token = await TokenService.getToken();
|
||||
final headers = token != null ? ApiConfig.authHeaders(token) : ApiConfig.headers;
|
||||
|
||||
final uri = Uri.parse('${ApiConfig.baseUrl}/absences-garde/$id');
|
||||
|
||||
@@ -96,7 +96,8 @@ class ApiConfig {
|
||||
};
|
||||
|
||||
static Map<String, String> authHeaders(String token) => {
|
||||
...headers,
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
'Authorization': 'Bearer $token',
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user