mirror of
https://github.com/sysadminsmedia/homebox.git
synced 2025-12-21 21:33:02 +01:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ae4b95301f |
@@ -45,7 +45,8 @@ class AuthContext implements IAuthContext {
|
|||||||
private _attachmentToken: CookieRef<string | null>;
|
private _attachmentToken: CookieRef<string | null>;
|
||||||
|
|
||||||
get token() {
|
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() {
|
get attachmentToken() {
|
||||||
@@ -66,11 +67,11 @@ class AuthContext implements IAuthContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isExpired() {
|
isExpired() {
|
||||||
return this.token;
|
return !this.token;
|
||||||
}
|
}
|
||||||
|
|
||||||
isAuthorized() {
|
isAuthorized() {
|
||||||
return !this.isExpired();
|
return this.token;
|
||||||
}
|
}
|
||||||
|
|
||||||
invalidateSession() {
|
invalidateSession() {
|
||||||
@@ -79,7 +80,6 @@ class AuthContext implements IAuthContext {
|
|||||||
// Delete the cookies
|
// Delete the cookies
|
||||||
this._token.value = null;
|
this._token.value = null;
|
||||||
this._attachmentToken.value = null;
|
this._attachmentToken.value = null;
|
||||||
|
|
||||||
console.log("Session invalidated");
|
console.log("Session invalidated");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,14 +3,18 @@ export default defineNuxtRouteMiddleware(async () => {
|
|||||||
const api = useUserApi();
|
const api = useUserApi();
|
||||||
|
|
||||||
if (!ctx.isAuthorized()) {
|
if (!ctx.isAuthorized()) {
|
||||||
return navigateTo("/");
|
if (window.location.pathname !== "/") {
|
||||||
|
return navigateTo("/");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ctx.user) {
|
if (!ctx.user) {
|
||||||
console.log("Fetching user data");
|
console.log("Fetching user data");
|
||||||
const { data, error } = await api.user.self();
|
const { data, error } = await api.user.self();
|
||||||
if (error) {
|
if (error) {
|
||||||
return navigateTo("/");
|
if (window.location.pathname !== "/") {
|
||||||
|
return navigateTo("/");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.user = data.item;
|
ctx.user = data.item;
|
||||||
|
|||||||
Reference in New Issue
Block a user