fix(dashboard): only clear token from localStorage on 401 error

This commit is contained in:
spiral 2022-06-02 23:12:38 -04:00
parent 66883cef51
commit f731f0d453
No known key found for this signature in database
GPG Key ID: 244A11E4B0BCF40E
2 changed files with 9 additions and 6 deletions

View File

@ -58,9 +58,9 @@
user = res; user = res;
} catch (error) { } catch (error) {
console.log(error); console.log(error);
localStorage.removeItem("pk-token"); // localStorage.removeItem("pk-token");
localStorage.removeItem("pk-user"); // localStorage.removeItem("pk-user");
currentUser.update(() => null); // currentUser.update(() => null);
navigate("/"); navigate("/");
} }
} }

View File

@ -47,9 +47,12 @@
currentUser.update(() => res); currentUser.update(() => res);
} catch (error) { } catch (error) {
console.log(error); console.log(error);
localStorage.removeItem("pk-token"); if (error.code == 401) {
localStorage.removeItem("pk-user"); error.message = "Invalid token";
currentUser.update(() => null); localStorage.removeItem("pk-token");
localStorage.removeItem("pk-user");
currentUser.update(() => null);
}
err = error.message; err = error.message;
} }
loading = false; loading = false;