Refactor token handling in InvenTreeAPI: reset token on request failure and save on success

This commit is contained in:
RaffaelW 2026-01-31 21:45:26 +01:00
parent 3b05b6fe54
commit 2f95ac3209

View file

@ -546,8 +546,6 @@ class InvenTreeAPI {
userProfile.token = token; userProfile.token = token;
profile = userProfile; profile = userProfile;
await UserProfileDBManager().updateProfile(userProfile);
final response = await get(_URL_ME); final response = await get(_URL_ME);
if (!response.successful()) { if (!response.successful()) {
@ -564,6 +562,13 @@ class InvenTreeAPI {
} }
debug("Request failed: STATUS ${response.statusCode}"); debug("Request failed: STATUS ${response.statusCode}");
// reset token
userProfile.token = "";
profile = userProfile;
} else {
// save token
await UserProfileDBManager().updateProfile(userProfile);
} }
return response; return response;