owltide/middleware/authenticated.ts
Hornwitser e722876aae
All checks were successful
/ build (push) Successful in 3m29s
/ deploy (push) Successful in 47s
Use a pinia store to manage account state
Refactor the existing scattered code dealing with the account state into
a pinia store.
2025-05-24 20:01:23 +02:00

19 lines
467 B
TypeScript

export default defineNuxtRouteMiddleware(async (to, from) => {
const accountStore = useAccountStore();
if (!accountStore.valid) {
console.log("Not logged in, redirecting to /login");
return navigateTo("/login");
}
if (
to.meta.allowedAccountTypes
&& !to.meta.allowedAccountTypes.includes(accountStore.type!)
) {
throw createError({
status: 403,
statusMessage: "Forbidden",
message: "You are not allowed to access this resource.",
})
}
})