auth middlewares

This commit is contained in:
2025-07-18 09:27:49 +02:00
parent 4ea8b62dc8
commit 22c9f455b9
8 changed files with 41 additions and 8 deletions

View File

@@ -0,0 +1,13 @@
export default defineNuxtRouteMiddleware((to, _from) => {
if (
useAuthSession().value != null ||
to.name === 'signin' ||
to.name === 'signup'
) {
return;
}
return navigateTo({
path: '/signin',
});
});

View File

@@ -0,0 +1,9 @@
export default defineNuxtRouteMiddleware((to, _from) => {
if (useAuthSession().value == null && to.name !== 'index') {
return;
}
return navigateTo({
path: '/',
});
});

View File

@@ -1,5 +0,0 @@
<template>
<section>
<h1>/about</h1>
</section>
</template>

View File

@@ -1,3 +1,9 @@
<script setup lang="ts">
definePageMeta({
middleware: ['authenticated'],
});
</script>
<template> <template>
<p>/</p> <p>/</p>
</template> </template>

View File

@@ -11,6 +11,7 @@ import { loginUser } from '~/lib/api/auth/login';
definePageMeta({ definePageMeta({
layout: 'auth', layout: 'auth',
middleware: ['not-authenticated'],
}); });
// TODO: Get this from the backend // TODO: Get this from the backend
@@ -86,7 +87,7 @@ function onKeyDown(e: KeyboardEvent) {
<Button class="w-full" variant="outline" :disabled="!OPEN_ID" <Button class="w-full" variant="outline" :disabled="!OPEN_ID"
>OpenID Connect</Button >OpenID Connect</Button
> >
<NuxtLink to="/register" class="w-full"> <NuxtLink to="/signup" class="w-full">
<Button class="w-full" variant="ghost">Sign up instead</Button> <Button class="w-full" variant="ghost">Sign up instead</Button>
</NuxtLink> </NuxtLink>
</CardFooter> </CardFooter>

View File

@@ -11,6 +11,7 @@ import { registerUser } from '~/lib/api/auth/register';
definePageMeta({ definePageMeta({
layout: 'auth', layout: 'auth',
middleware: ['not-authenticated'],
}); });
const registering = ref(false); const registering = ref(false);
@@ -35,7 +36,7 @@ async function submit() {
); );
if (success) { if (success) {
await navigateTo({ path: '/login' }); await navigateTo({ path: '/signin' });
return; return;
} }
@@ -90,7 +91,7 @@ async function submit() {
@click="submit" @click="submit"
>Sign up</Button >Sign up</Button
> >
<NuxtLink to="/login" class="w-full"> <NuxtLink to="/signin" class="w-full">
<Button class="w-full" variant="ghost">Sign in instead</Button> <Button class="w-full" variant="ghost">Sign in instead</Button>
</NuxtLink> </NuxtLink>
</CardFooter> </CardFooter>

View File

@@ -3,6 +3,10 @@ import DirectoryListContextMenu from '~/components/DirectoryListContextMenu.vue'
import RenameEntryDialog from '~/components/actions/RenameEntryDialog.vue'; import RenameEntryDialog from '~/components/actions/RenameEntryDialog.vue';
import { getWarrenDirectory } from '~/lib/api/warrens'; import { getWarrenDirectory } from '~/lib/api/warrens';
definePageMeta({
middleware: ['authenticated'],
});
const entries = useAsyncData('current-directory', () => const entries = useAsyncData('current-directory', () =>
getWarrenDirectory(useWarrenRoute().value) getWarrenDirectory(useWarrenRoute().value)
).data; ).data;

View File

@@ -1,6 +1,10 @@
<script setup lang="ts"> <script setup lang="ts">
import { ScrollArea } from '@/components/ui/scroll-area'; import { ScrollArea } from '@/components/ui/scroll-area';
definePageMeta({
middleware: ['authenticated'],
});
const store = useWarrenStore(); const store = useWarrenStore();
</script> </script>