Files
drop/server/middleware/require-user.global.ts
T
DecDuck 661a30107c object storage + full permission system + testing
Object storage now works fully, with the permission system. It still
needs additional external endpoints for updating and deleting objects
from the API, but it is otherwise complete. Further tasks include
writing an S3 adapter.
2024-10-09 14:43:06 +11:00

16 lines
439 B
TypeScript

const whitelistedPrefixes = ["/signin", "/register", "/api"];
export default defineNuxtRouteMiddleware(async (to, from) => {
if (import.meta.server) return;
if (whitelistedPrefixes.findIndex((e) => to.fullPath.startsWith(e)) != -1)
return;
const user = useUser();
if (user === undefined) {
await updateUser();
}
if (!user.value) {
return navigateTo({ path: "/signin", query: { redirect: to.fullPath } });
}
});