Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<div
class="flex min-h-screen flex-col bg-white text-gray-900 transition-colors duration-300 dark:bg-gray-900 dark:text-gray-100"
>

<main class="flex-1">
<NuxtLayout>
<NuxtPage />
Expand Down
18 changes: 16 additions & 2 deletions app/middleware/auth.global.ts
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stale commits

Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,27 @@ export default defineNuxtRouteMiddleware(async (to) => {
return navigateTo('/auth')
}

if (session.value && to.path === '/auth') {
if (!session.value) {
return
}

const userRole = (session.value.user as { role?: string } | undefined)?.role

if (to.path === '/') {
return navigateTo(userRole === 'admin' ? '/admin' : '/reader/profile')
}

if (to.path === '/auth') {
const role = to.query.role

if (role === 'admin') {
return navigateTo('/admin')
return navigateTo(userRole === 'admin' ? '/admin' : '/')
}

return navigateTo('/reader/profile')
}

if (to.path.startsWith('/admin') && userRole !== 'admin') {
return navigateTo('/')
}
})
Loading