Skip to content

Commit

Permalink
Merge pull request #38 from OpenWebconcept/development
Browse files Browse the repository at this point in the history
Development to main
  • Loading branch information
remko48 authored Feb 23, 2024
2 parents 7f9d6c3 + f12379e commit 3e4f5b5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/features/login/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const anonymousUser = Object.freeze({
async function fetchUser(url: string): Promise<User> {
const response = await fetch(url, {
headers: {
Authorization: `Bearer ${Cookies.get("jwt")}`,
Authorization: `Bearer ${Cookies.get("jwt") ?? window.sessionStorage.getItem("jwt")}`,
},
});

Expand Down Expand Up @@ -45,5 +45,6 @@ export const logOut = () =>
} else {
Cookies.remove("jwt");
Cookies.remove("userId");
window.sessionStorage.removeItem("jwt")
}
});
7 changes: 4 additions & 3 deletions src/services/fetch-logged-in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type FetchArgs = Parameters<typeof fetch>;
type FetchReturn = ReturnType<typeof fetch>;

// eslint-disable-next-line @typescript-eslint/no-empty-function
const empty = () => {};
const empty = () => { };

const waitForLogin = {
promise: Promise.resolve(),
Expand All @@ -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] || {};
Expand All @@ -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")}`,
},
};

Expand All @@ -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;

Expand Down
1 change: 1 addition & 0 deletions src/views/LoginView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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("/");
}
Expand Down

0 comments on commit 3e4f5b5

Please sign in to comment.