diff --git a/src/features/login/service.ts b/src/features/login/service.ts index eeaa7c1..90006e4 100644 --- a/src/features/login/service.ts +++ b/src/features/login/service.ts @@ -10,7 +10,7 @@ const anonymousUser = Object.freeze({ async function fetchUser(url: string): Promise { const response = await fetch(url, { headers: { - Authorization: `Bearer ${Cookies.get("jwt")}`, + Authorization: `Bearer ${Cookies.get("jwt") ?? window.sessionStorage.getItem("jwt")}`, }, }); @@ -45,5 +45,6 @@ export const logOut = () => } else { Cookies.remove("jwt"); Cookies.remove("userId"); + window.sessionStorage.removeItem("jwt") } }); diff --git a/src/services/fetch-logged-in.ts b/src/services/fetch-logged-in.ts index 81e702d..e87400d 100644 --- a/src/services/fetch-logged-in.ts +++ b/src/services/fetch-logged-in.ts @@ -6,7 +6,7 @@ type FetchArgs = Parameters; type FetchReturn = ReturnType; // eslint-disable-next-line @typescript-eslint/no-empty-function -const empty = () => {}; +const empty = () => { }; const waitForLogin = { promise: Promise.resolve(), @@ -33,6 +33,7 @@ export function fetchLoggedIn(...args: FetchArgs): FetchReturn { if (!validateSession()) { Cookies.remove("jwt"); Cookies.remove("userId"); + window.sessionStorage.removeItem("jwt") } const init = args[1] || {}; @@ -48,7 +49,7 @@ export function fetchLoggedIn(...args: FetchArgs): FetchReturn { ...options, headers: { ...options?.headers, - Authorization: `Bearer ${Cookies.get("jwt")}`, + Authorization: `Bearer ${Cookies.get("jwt") ?? window.sessionStorage.getItem("jwt")}`, }, }; @@ -64,7 +65,7 @@ export function fetchLoggedIn(...args: FetchArgs): FetchReturn { } const validateSession = () => { - const token = Cookies.get("jwt"); + const token = Cookies.get("jwt") ?? window.sessionStorage.getItem("jwt"); if (!token) return false; diff --git a/src/views/LoginView.vue b/src/views/LoginView.vue index e524b59..8c04506 100644 --- a/src/views/LoginView.vue +++ b/src/views/LoginView.vue @@ -71,6 +71,7 @@ async function handleSubmit() { Cookies.set("userId", data.id); Cookies.set("jwt", data.jwtToken); + window.sessionStorage.setItem("jwt", data.jwtToken) router.push("/"); }