token fix

This commit is contained in:
Deep Koluguri 2025-11-10 23:00:58 -05:00
parent 15392d3604
commit c059e4d8bf
1 changed files with 11 additions and 3 deletions

View File

@ -41,9 +41,17 @@ static const String tokenKey = 'auth_token';
onError: (error, handler) { onError: (error, handler) {
print('❌ [ApiService] Error: ${error.response?.statusCode} - ${error.message}'); print('❌ [ApiService] Error: ${error.response?.statusCode} - ${error.message}');
if (error.response?.statusCode == 401) { if (error.response?.statusCode == 401) {
print('❌ [ApiService] 401 Unauthorized - Clearing token'); print('❌ [ApiService] 401 Unauthorized detected');
// Token expired or invalid // Only clear token if the error message indicates token is expired/invalid
final errorMessage = error.response?.data?['message']?.toString() ?? '';
if (errorMessage.contains('Token expired') ||
errorMessage.contains('Invalid token') ||
errorMessage.contains('Authentication required')) {
print('❌ [ApiService] Token is invalid/expired - Clearing token');
_clearToken(); _clearToken();
} else {
print('⚠️ [ApiService] 401 but token might be valid - NOT clearing (backend issue?)');
}
} }
handler.next(error); handler.next(error);
}, },