mirror of
https://github.com/hay-kot/homebox.git
synced 2024-11-25 01:55:43 +00:00
6e203e7833
Former-commit-id: ae4b95301f
22 lines
483 B
TypeScript
22 lines
483 B
TypeScript
export default defineNuxtRouteMiddleware(async () => {
|
|
const ctx = useAuthContext();
|
|
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;
|
|
}
|
|
});
|