15 lines
388 B
TypeScript
15 lines
388 B
TypeScript
export default defineNuxtRouteMiddleware((to, _from) => {
|
|
const { isAuthenticated } = useAuth();
|
|
const allowedUnauthenticatedPaths: string[] = ['/', '/login'];
|
|
if (allowedUnauthenticatedPaths.find((p) => p === to.path)) {
|
|
return;
|
|
}
|
|
if (!isAuthenticated.value) {
|
|
return navigateTo({
|
|
path: '/login',
|
|
query: { redirect: to.fullPath },
|
|
});
|
|
}
|
|
return;
|
|
});
|