Skip to content
This repository was archived by the owner on Jun 12, 2024. It is now read-only.

Commit ae4b953

Browse files
authored
fix: infinite redirect issue (#583)
1 parent d8482f3 commit ae4b953

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

Diff for: frontend/composables/use-auth-context.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ class AuthContext implements IAuthContext {
4545
private _attachmentToken: CookieRef<string | null>;
4646

4747
get token() {
48-
return this._token.value === "true";
48+
// @ts-ignore sometimes it's a boolean I guess?
49+
return this._token.value === "true" || this._token.value === true;
4950
}
5051

5152
get attachmentToken() {
@@ -66,11 +67,11 @@ class AuthContext implements IAuthContext {
6667
}
6768

6869
isExpired() {
69-
return this.token;
70+
return !this.token;
7071
}
7172

7273
isAuthorized() {
73-
return !this.isExpired();
74+
return this.token;
7475
}
7576

7677
invalidateSession() {
@@ -79,7 +80,6 @@ class AuthContext implements IAuthContext {
7980
// Delete the cookies
8081
this._token.value = null;
8182
this._attachmentToken.value = null;
82-
8383
console.log("Session invalidated");
8484
}
8585

Diff for: frontend/middleware/auth.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@ export default defineNuxtRouteMiddleware(async () => {
33
const api = useUserApi();
44

55
if (!ctx.isAuthorized()) {
6-
return navigateTo("/");
6+
if (window.location.pathname !== "/") {
7+
return navigateTo("/");
8+
}
79
}
810

911
if (!ctx.user) {
1012
console.log("Fetching user data");
1113
const { data, error } = await api.user.self();
1214
if (error) {
13-
return navigateTo("/");
15+
if (window.location.pathname !== "/") {
16+
return navigateTo("/");
17+
}
1418
}
1519

1620
ctx.user = data.item;

0 commit comments

Comments
 (0)