feat (error-pages): add custom error pages

This commit is contained in:
Abizrh
2025-08-12 13:16:07 +07:00
parent 125d7857ce
commit dc5e7d48da
9 changed files with 183 additions and 13 deletions
+26
View File
@@ -0,0 +1,26 @@
<script setup>
definePageMeta({
layout: 'blank',
})
const router = useRouter()
</script>
<template>
<div class="h-svh">
<div class="m-auto flex h-full w-full flex-col items-center justify-center gap-2">
<h1 class="text-[7rem] font-bold leading-tight">404</h1>
<span class="font-medium">Oops! Page Not Found!</span>
<p class="text-muted-foreground text-center">
It seems like the page you're looking for <br />
does not exist or might have been removed.
</p>
<div class="mt-6 flex gap-4">
<Button variant="outline" @click="router.back()"> Go Back </Button>
<Button @click="router.push('/')"> Back to Home </Button>
</div>
</div>
</div>
</template>
<style scoped></style>
+1 -1
View File
@@ -9,7 +9,7 @@ export default defineNuxtRouteMiddleware((to) => {
console.log('currRole', userStore.userRole)
console.log('isAuth', userStore.isAuthenticated)
if (!userStore.isAuthenticated) {
return navigateTo('/auth/login')
return navigateTo('/401')
}
// const allowedRoles = to.meta.roles as string[] | undefined
+2 -8
View File
@@ -11,10 +11,7 @@ export default defineNuxtRouteMiddleware((to) => {
if (pagePermissions) {
const { checkRole } = useRBAC()
if (!checkRole(pagePermissions)) {
throw createError({
statusCode: 403,
statusMessage: 'Forbidden - Insufficient permissions for this page',
})
return navigateTo('/403')
}
}
@@ -27,10 +24,7 @@ export default defineNuxtRouteMiddleware((to) => {
const hasRequiredRole = requiredRoles.some((role) => userRoles.includes(role))
if (!hasRequiredRole) {
throw createError({
statusCode: 403,
statusMessage: 'Forbidden - Insufficient role permissions',
})
return navigateTo('/403')
}
}
}
+26
View File
@@ -0,0 +1,26 @@
<script setup>
definePageMeta({
layout: 'blank',
})
const router = useRouter()
</script>
<template>
<div class="h-svh">
<div class="m-auto flex h-full w-full flex-col items-center justify-center gap-2">
<h1 class="text-[7rem] font-bold leading-tight">401</h1>
<span class="font-medium">Unauthorized Access</span>
<p class="text-muted-foreground text-center">
Please log in with the appropriate credentials <br />
to access this resource.
</p>
<div class="mt-6 flex gap-4">
<Button variant="outline" @click="router('/auth/login')"> Login </Button>
<Button @click="router.push('/')"> Back to Home </Button>
</div>
</div>
</div>
</template>
<style scoped></style>
+34
View File
@@ -0,0 +1,34 @@
<script setup>
definePageMeta({
layout: 'blank',
})
const router = useRouter()
</script>
<template>
<div class="h-svh">
<div class="m-auto h-full w-full flex flex-col items-center justify-center gap-2">
<h1 class="text-[7rem] font-bold leading-tight">
403
</h1>
<span class="font-medium">Access Forbidden</span>
<p class="text-center text-muted-foreground">
You don't have necessary permission <br>
to view this resource.
</p>
<div class="mt-6 flex gap-4">
<Button variant="outline" @click="router.back()">
Go Back
</Button>
<Button @click="router.push('/')">
Back to Home
</Button>
</div>
</div>
</div>
</template>
<style scoped>
</style>
+34
View File
@@ -0,0 +1,34 @@
<script setup>
definePageMeta({
layout: 'blank',
})
const router = useRouter()
</script>
<template>
<div class="h-svh">
<div class="m-auto h-full w-full flex flex-col items-center justify-center gap-2">
<h1 class="text-[7rem] font-bold leading-tight">
404
</h1>
<span class="font-medium">Oops! Page Not Found!</span>
<p class="text-center text-muted-foreground">
It seems like the page you're looking for <br>
does not exist or might have been removed.
</p>
<div class="mt-6 flex gap-4">
<Button variant="outline" @click="router.back()">
Go Back
</Button>
<Button @click="router.push('/')">
Back to Home
</Button>
</div>
</div>
</div>
</template>
<style scoped>
</style>
+33
View File
@@ -0,0 +1,33 @@
<script setup>
definePageMeta({
layout: 'blank',
})
const router = useRouter()
</script>
<template>
<div class="h-svh">
<div class="m-auto h-full w-full flex flex-col items-center justify-center gap-2">
<h1 class="text-[7rem] font-bold leading-tight">
500
</h1>
<span class="font-medium">Oops! Something went wrong :')</span>
<p class="text-center text-muted-foreground">
We apologize for the inconvenience. <br> Please try again later.
</p>
<div class="mt-6 flex gap-4">
<Button variant="outline" @click="router.back()">
Go Back
</Button>
<Button @click="router.push('/')">
Back to Home
</Button>
</div>
</div>
</div>
</template>
<style scoped>
</style>
+26
View File
@@ -0,0 +1,26 @@
<script setup>
definePageMeta({
layout: 'blank',
})
const router = useRouter()
</script>
<template>
<div class="h-svh">
<div class="m-auto flex h-full w-full flex-col items-center justify-center gap-2">
<h1 class="text-[7rem] font-bold leading-tight">503</h1>
<span class="font-medium">Website is under maintenance!</span>
<p class="text-muted-foreground text-center">
The site is not available at the moment. <br />
We'll be back online shortly.
</p>
<div class="mt-6 flex gap-4">
<Button variant="outline" @click="router.back()"> Go Back </Button>
<Button @click="router.push('/')"> Back to Home </Button>
</div>
</div>
</div>
</template>
<style scoped></style>
+1 -4
View File
@@ -16,10 +16,7 @@ const { checkRole, hasReadAccess } = useRBAC()
// Check if user has access to this page
const hasAccess = checkRole(roleAccess)
if (!hasAccess) {
throw createError({
statusCode: 403,
statusMessage: 'Access denied',
})
navigateTo('/403')
}
// Define permission-based computed properties