Implement account type restricted page

Add allowedAccountTypes page metadata which the authenticated middleware
uses to further restrict the types of accounts that can access the page.

If the account type is insufficent to access the page it will return an
HTTP 403 Forbidden status, which is rendered using the error page.
This commit is contained in:
Hornwitser 2025-03-09 22:21:13 +01:00
parent 245169950a
commit e8226e0062
6 changed files with 82 additions and 3 deletions

13
pages/edit.vue Normal file
View file

@ -0,0 +1,13 @@
<template>
<main>
<h1>Edit</h1>
<p>Todo: implement editing</p>
</main>
</template>
<script lang="ts" setup>
definePageMeta({
middleware: ["authenticated"],
allowedAccountTypes: ["crew", "admin"],
})
</script>

View file

@ -3,8 +3,21 @@
<h1>Schedule Demo</h1>
<ul>
<li>
<NuxtLink to="/schedule">Schedule demo</NuxtLink>
<NuxtLink to="/schedule">View Schedule</NuxtLink>
</li>
<li v-if="session?.account?.type === 'admin' || session?.account?.type === 'crew'">
<NuxtLink to="/edit">Edit Schedule</NuxtLink>
</li>
<li v-if="session">
<NuxtLink to="/account/settings">Account Settings</NuxtLink>
</li>
<li v-if="!session">
<NuxtLink to="/login">Log In / Create Account</NuxtLink>
</li>
</ul>
</main>
</template>
<script lang="ts" setup>
const { data: session } = await useAccountSession();
</script>