9f86acacb0
- roleMenuItems.js: merged menu builder that unions items from all user roles (student + missionary, student + counselor, etc.) additively - auth store: expose `roles` array in addition to singular `role`; wire in WordPress auth-status cookie sync so the public site can show/hide the account button - router guards: use roles.includes() instead of role === for multi-role access - layouts (Student/Counselor/Missionary): delegate menuItems to buildMergedMenuItems so dual-role users see sections from both roles - StudentSessionDetailsPage: contentKind now returns 'video' (not 'link') when session.videoUrl is set; adds embed iframe branch for online sessions - CertificateItem.vue: fix CSS order/alignment for desktop + mobile layout - StudentCertificatesPage.vue: map backend payload fields to component props with Jalaali date formatting - SessionFormPage: upload progress bar (%) during video uploads; embed_code textarea for online sessions (frontend-only; dormant until batch-2 backend migration is deployed) - wp-sync/auth-status-cookie.js: cookie helper for WordPress login-state sync [batch-1-low-risk]
56 lines
1.5 KiB
JavaScript
56 lines
1.5 KiB
JavaScript
import { ROLE_HOME_ROUTES } from '@/enums'
|
|
import { useAuthStore } from '@/store/auth'
|
|
import { tokenService } from '@/services/api/token-service'
|
|
|
|
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 { name: ROLE_HOME_ROUTES[auth.role] || 'student-dashboard' }
|
|
}
|
|
return
|
|
}
|
|
|
|
// Students whose account is not yet `approved` (pending/verified) must finish
|
|
// the registration wizard before reaching any authenticated page.
|
|
export const statusGuard = (to) => {
|
|
if (isPublic(to)) return
|
|
if (to.meta?.requiresGuest) return
|
|
if (to.name === 'student-register') return
|
|
if (!tokenService.hasToken()) return
|
|
const auth = useAuthStore()
|
|
if (!auth.user) return
|
|
if (!auth.roles.includes('student')) return
|
|
if (auth.user.status === 'approved') return
|
|
return { name: 'student-register' }
|
|
}
|
|
|
|
export const roleGuard = (to) => {
|
|
if (!to.meta?.role) return
|
|
const auth = useAuthStore()
|
|
if (!auth.roles.includes(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, statusGuard, roleGuard]
|