auth middlewares
This commit is contained in:
13
frontend/middleware/authenticated.ts
Normal file
13
frontend/middleware/authenticated.ts
Normal 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',
|
||||||
|
});
|
||||||
|
});
|
||||||
9
frontend/middleware/not-authenticated.ts
Normal file
9
frontend/middleware/not-authenticated.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
export default defineNuxtRouteMiddleware((to, _from) => {
|
||||||
|
if (useAuthSession().value == null && to.name !== 'index') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return navigateTo({
|
||||||
|
path: '/',
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
<template>
|
|
||||||
<section>
|
|
||||||
<h1>/about</h1>
|
|
||||||
</section>
|
|
||||||
</template>
|
|
||||||
@@ -1,3 +1,9 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
definePageMeta({
|
||||||
|
middleware: ['authenticated'],
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<p>/</p>
|
<p>/</p>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -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>
|
||||||
@@ -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>
|
||||||
@@ -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;
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user