2025-04-01 18:18:57 +11:00
|
|
|
const whitelistedPrefixes = ["/auth", "/api", "/setup"];
|
2024-10-11 00:37:08 +11:00
|
|
|
const requireAdmin = ["/admin"];
|
2024-10-07 22:35:54 +11:00
|
|
|
|
2025-04-15 21:43:27 -04:00
|
|
|
export default defineNuxtRouteMiddleware(async (to, _from) => {
|
2024-10-11 00:37:08 +11:00
|
|
|
const error = useError();
|
|
|
|
|
if (error.value !== undefined) return;
|
2024-10-07 22:35:54 +11:00
|
|
|
if (whitelistedPrefixes.findIndex((e) => to.fullPath.startsWith(e)) != -1)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const user = useUser();
|
2026-06-21 20:07:59 +10:00
|
|
|
if (user.value === undefined) {
|
2024-10-07 22:35:54 +11:00
|
|
|
await updateUser();
|
|
|
|
|
}
|
|
|
|
|
if (!user.value) {
|
2025-03-22 15:54:43 -04:00
|
|
|
return navigateTo({
|
|
|
|
|
path: "/auth/signin",
|
|
|
|
|
query: { redirect: to.fullPath },
|
|
|
|
|
});
|
2024-10-07 22:35:54 +11:00
|
|
|
}
|
2024-10-11 00:37:08 +11:00
|
|
|
if (
|
|
|
|
|
requireAdmin.findIndex((e) => to.fullPath.startsWith(e)) != -1 &&
|
|
|
|
|
!user.value.admin
|
|
|
|
|
) {
|
|
|
|
|
return navigateTo({ path: "/" });
|
|
|
|
|
}
|
2024-10-07 22:35:54 +11:00
|
|
|
});
|