token fix
This commit is contained in:
parent
15392d3604
commit
c059e4d8bf
|
|
@ -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
|
||||||
_clearToken();
|
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);
|
handler.next(error);
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue