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:
2026-08-03 15:19:50 +02:00
co-authored by Cursor
parent 32c15dbd1d
commit d97bcea99e
10 changed files with 501 additions and 6 deletions
+29
View File
@@ -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