80 lines
2.4 KiB
Vue
80 lines
2.4 KiB
Vue
<script setup lang="ts">
|
|
import { ref, onMounted } from 'vue';
|
|
import { useRouter, useRoute } from 'vue-router';
|
|
import { useAuth } from '~/composables/useAuth';
|
|
import { getUserAccess } from '~/services/access';
|
|
import type { SessionResponse } from '~/types/auth';
|
|
|
|
/*-For Set Blank Layout-*/
|
|
definePageMeta({
|
|
layout: "blank",
|
|
middleware: [] // Skip auth middleware for this page
|
|
});
|
|
|
|
const router = useRouter();
|
|
const route = useRoute();
|
|
const { user, logout } = useAuth();
|
|
|
|
const requestedPath = ref('');
|
|
|
|
onMounted(() => {
|
|
// Get the path from query or from document.referrer
|
|
requestedPath.value = (route.query.path as string) || 'Unknown';
|
|
|
|
});
|
|
|
|
//loading gotodashboard
|
|
const loading = ref(false);
|
|
|
|
|
|
const goToDashboard = async () => {
|
|
try {
|
|
loading.value = true;
|
|
const IdToken = localStorage.getItem('idToken');
|
|
|
|
if (!user.value || !IdToken) {
|
|
router.push('/login');
|
|
return;
|
|
}
|
|
// Check user access
|
|
const userAccess = await getUserAccess(user.value?.id, IdToken);
|
|
|
|
if (userAccess && userAccess.data) {
|
|
loading.value = false;
|
|
router.push('/dashboard');
|
|
} else {
|
|
loading.value = false;
|
|
await logout();
|
|
}
|
|
} catch (error) {
|
|
console.error('❌ Error checking user access:', error);
|
|
await logout();
|
|
}
|
|
};
|
|
</script>
|
|
<template>
|
|
<div class="d-flex justify-center align-center text-center h-100vh bg-primary">
|
|
<div>
|
|
<img src="@/assets/images/backgrounds/error-access-denied.svg" width="400" alt="Access Denied" />
|
|
<h1 class="text-h1 pt-3">Access Denied!</h1>
|
|
<h4 class="text-h4 my-4">You don't have permission to access this page.</h4>
|
|
|
|
<!-- Show requested path if available -->
|
|
<div v-if="requestedPath && requestedPath !== 'Unknown'" class="my-4">
|
|
<v-chip color="white" variant="outlined" size="small">
|
|
Requested: {{ requestedPath }}
|
|
</v-chip>
|
|
</div>
|
|
|
|
<!-- Show user info -->
|
|
|
|
|
|
<p class="text-body-1 my-4" style="color: rgba(255,255,255,0.8)">
|
|
Contact your administrator if you believe this is an error.
|
|
</p>
|
|
|
|
<v-btn :loading="loading" flat variant="outlined" :prepend-icon="'mdi-arrow-left'" color="white" class="mb-4" @click="goToDashboard">Go To Back Page</v-btn>
|
|
</div>
|
|
</div>
|
|
</template>
|