first commit

This commit is contained in:
sajjadtalkhabi
2026-05-13 01:43:05 +03:30
commit d2a577f254
297 changed files with 36274 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
import { tokenService } from '@/services/api/token-service'
import { useAuthStore } from '@/store/auth'
const APP_TITLE = 'بنو'
const isPublic = (to) => to.meta?.public === true
export const authGuard = (to) => {
if (isPublic(to)) return
if (to.meta?.requiresGuest) return
if (!tokenService.hasToken()) {
return { name: 'login', query: { redirect: to.fullPath } }
}
return
}
export const guestGuard = (to) => {
if (!to.meta?.requiresGuest) return
if (tokenService.hasToken()) {
const auth = useAuthStore()
return auth.role === 'admin' ? { name: 'admin-dashboard' } : { name: 'student-dashboard' }
}
return
}
export const roleGuard = (to) => {
if (!to.meta?.role) return
const auth = useAuthStore()
if (auth.role !== to.meta.role) {
return { name: 'home' }
}
return
}
export const titleGuard = (to) => {
const title = to.meta?.title
document.title = title ? `${APP_TITLE} - ${title}` : APP_TITLE
}
export const guards = [authGuard, guestGuard, roleGuard]