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;
} catch (error) {
console.log(error);
localStorage.removeItem("pk-token");
localStorage.removeItem("pk-user");
currentUser.update(() => null);
// localStorage.removeItem("pk-token");
// localStorage.removeItem("pk-user");
// currentUser.update(() => null);
navigate("/");
}
}

View File

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