token fix
This commit is contained in:
parent
15392d3604
commit
c059e4d8bf
|
|
@ -41,9 +41,17 @@ static const String tokenKey = 'auth_token';
|
|||
onError: (error, handler) {
|
||||
print('❌ [ApiService] Error: ${error.response?.statusCode} - ${error.message}');
|
||||
if (error.response?.statusCode == 401) {
|
||||
print('❌ [ApiService] 401 Unauthorized - Clearing token');
|
||||
// Token expired or invalid
|
||||
print('❌ [ApiService] 401 Unauthorized detected');
|
||||
// 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();
|
||||
} else {
|
||||
print('⚠️ [ApiService] 401 but token might be valid - NOT clearing (backend issue?)');
|
||||
}
|
||||
}
|
||||
handler.next(error);
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue