feat: мультироль
🚀 Create and publish a Docker image / Detect changes in backend and frontend (push) Successful in 9s
🚀 Create and publish a Docker image / Build & publish backend image (push) Successful in 2m6s
🚀 Create and publish a Docker image / Build & publish frontend image (push) Successful in 26s
🚀 Create and publish a Docker image / Update stack on Portainer (push) Successful in 6s
🚀 Create and publish a Docker image / Detect changes in backend and frontend (push) Successful in 9s
🚀 Create and publish a Docker image / Build & publish backend image (push) Successful in 2m6s
🚀 Create and publish a Docker image / Build & publish frontend image (push) Successful in 26s
🚀 Create and publish a Docker image / Update stack on Portainer (push) Successful in 6s
This commit is contained in:
@@ -39,16 +39,19 @@ const router = createRouter({
|
||||
|
||||
router.beforeEach(async (to) => {
|
||||
const auth = useAuthStore()
|
||||
const resolveDefaultRoute = () => {
|
||||
if (auth.user?.activeRole === 'teacher') return '/teacher'
|
||||
if (auth.user?.activeRole === 'admin') return '/admin'
|
||||
return '/'
|
||||
}
|
||||
if (!auth.initialized && !to.meta.public) {
|
||||
await auth.initialize()
|
||||
}
|
||||
if (!to.meta.public && !auth.isAuthenticated) {
|
||||
return '/login'
|
||||
}
|
||||
if (to.meta.role && auth.user && auth.user.role !== to.meta.role) {
|
||||
if (auth.user.role === 'teacher') return '/teacher'
|
||||
if (auth.user.role === 'admin') return '/admin'
|
||||
return '/'
|
||||
if (to.meta.role && auth.user && !auth.user.roles.includes(to.meta.role as 'student' | 'teacher' | 'admin')) {
|
||||
return resolveDefaultRoute()
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user