Add admin login page with session auth, route guard, and RTL form layout.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,12 +1,20 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
import AdminShell from '@/layouts/AdminShell.vue'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(import.meta.env.BASE_URL),
|
||||
routes: [
|
||||
{
|
||||
path: '/login',
|
||||
name: 'login',
|
||||
component: () => import('@/views/auth/LoginView.vue'),
|
||||
meta: { public: true, title: 'ورود به پنل مدیریت' },
|
||||
},
|
||||
{
|
||||
path: '/',
|
||||
component: AdminShell,
|
||||
meta: { requiresAuth: true },
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
@@ -102,4 +110,25 @@ const router = createRouter({
|
||||
],
|
||||
})
|
||||
|
||||
router.beforeEach((to) => {
|
||||
const auth = useAuthStore()
|
||||
auth.hydrate()
|
||||
|
||||
if (to.meta.public) {
|
||||
if (auth.isAuthenticated && to.name === 'login') {
|
||||
return { name: 'dashboard' }
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
if (to.matched.some((record) => record.meta.requiresAuth) && !auth.isAuthenticated) {
|
||||
return {
|
||||
name: 'login',
|
||||
query: { redirect: to.fullPath },
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
})
|
||||
|
||||
export default router
|
||||
|
||||
Reference in New Issue
Block a user