From 2f95ac32091b1262af22025d803a03dbe19dc795 Mon Sep 17 00:00:00 2001 From: RaffaelW <146560011+RaffaelW@users.noreply.github.com> Date: Sat, 31 Jan 2026 21:45:26 +0100 Subject: [PATCH] Refactor token handling in InvenTreeAPI: reset token on request failure and save on success --- lib/api.dart | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/api.dart b/lib/api.dart index cf6907e..61a9209 100644 --- a/lib/api.dart +++ b/lib/api.dart @@ -546,8 +546,6 @@ class InvenTreeAPI { userProfile.token = token; profile = userProfile; - await UserProfileDBManager().updateProfile(userProfile); - final response = await get(_URL_ME); if (!response.successful()) { @@ -564,6 +562,13 @@ class InvenTreeAPI { } debug("Request failed: STATUS ${response.statusCode}"); + + // reset token + userProfile.token = ""; + profile = userProfile; + } else { + // save token + await UserProfileDBManager().updateProfile(userProfile); } return response;