mirror of
https://github.com/hay-kot/homebox.git
synced 2024-11-22 00:25:43 +00:00
parent
0ef9d0deb8
commit
6e203e7833
2 changed files with 10 additions and 6 deletions
|
@ -45,7 +45,8 @@ class AuthContext implements IAuthContext {
|
|||
private _attachmentToken: CookieRef<string | null>;
|
||||
|
||||
get token() {
|
||||
return this._token.value === "true";
|
||||
// @ts-ignore sometimes it's a boolean I guess?
|
||||
return this._token.value === "true" || this._token.value === true;
|
||||
}
|
||||
|
||||
get attachmentToken() {
|
||||
|
@ -66,11 +67,11 @@ class AuthContext implements IAuthContext {
|
|||
}
|
||||
|
||||
isExpired() {
|
||||
return this.token;
|
||||
return !this.token;
|
||||
}
|
||||
|
||||
isAuthorized() {
|
||||
return !this.isExpired();
|
||||
return this.token;
|
||||
}
|
||||
|
||||
invalidateSession() {
|
||||
|
@ -79,7 +80,6 @@ class AuthContext implements IAuthContext {
|
|||
// Delete the cookies
|
||||
this._token.value = null;
|
||||
this._attachmentToken.value = null;
|
||||
|
||||
console.log("Session invalidated");
|
||||
}
|
||||
|
||||
|
|
|
@ -3,15 +3,19 @@ export default defineNuxtRouteMiddleware(async () => {
|
|||
const api = useUserApi();
|
||||
|
||||
if (!ctx.isAuthorized()) {
|
||||
if (window.location.pathname !== "/") {
|
||||
return navigateTo("/");
|
||||
}
|
||||
}
|
||||
|
||||
if (!ctx.user) {
|
||||
console.log("Fetching user data");
|
||||
const { data, error } = await api.user.self();
|
||||
if (error) {
|
||||
if (window.location.pathname !== "/") {
|
||||
return navigateTo("/");
|
||||
}
|
||||
}
|
||||
|
||||
ctx.user = data.item;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue