Files
crewli-old/apps/admin/src/plugins/1.router/additional-routes.ts
bert.hausmans 5e2ede14b4 fix(admin): index redirect uses auth cookies and Spatie roles
- Gate redirect on userData + accessToken; map org roles to events route
- Keep legacy admin/client role redirects for compatibility
- Rename organizer app HTML title to Event Crew - App
- Add Cursor database rules (ULID, JSON, indexes, soft deletes)

Made-with: Cursor
2026-03-30 10:32:42 +02:00

93 lines
2.7 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { RouteRecordRaw } from 'vue-router/auto'
const emailRouteComponent = () => import('@/pages/apps/email/index.vue')
// 👉 Redirects
export const redirects: RouteRecordRaw[] = [
// We are redirecting to different pages based on role.
// NOTE: Role is just for UI purposes. ACL is based on abilities.
{
path: '/',
name: 'index',
redirect: to => {
const userData = useCookie<Record<string, unknown> | null | undefined>('userData')
const accessToken = useCookie<string | null | undefined>('accessToken')
const isLoggedIn = !!(userData.value && accessToken.value)
if (!isLoggedIn)
return { name: 'login', query: to.query }
// Laravel API + Spatie: `roles` is string[] (e.g. super_admin, org_admin)
const roles = Array.isArray(userData.value?.roles)
? (userData.value!.roles as string[])
: []
const legacyRole = userData.value?.role as string | undefined
if (legacyRole === 'admin')
return { name: 'dashboards-crm' }
if (legacyRole === 'client')
return { name: 'access-control' }
const isOrgUser = roles.some(r =>
['super_admin', 'org_admin', 'org_member', 'org_readonly'].includes(r),
)
if (isOrgUser)
return { name: 'events' }
// Authenticated but unexpected role payload — avoid redirect loop back to login
return { name: 'events' }
},
},
{
path: '/pages/user-profile',
name: 'pages-user-profile',
redirect: () => ({ name: 'pages-user-profile-tab', params: { tab: 'profile' } }),
},
{
path: '/pages/account-settings',
name: 'pages-account-settings',
redirect: () => ({ name: 'pages-account-settings-tab', params: { tab: 'account' } }),
},
]
export const routes: RouteRecordRaw[] = [
// Email filter
{
path: '/apps/email/filter/:filter',
name: 'apps-email-filter',
component: emailRouteComponent,
meta: {
navActiveLink: 'apps-email',
layoutWrapperClasses: 'layout-content-height-fixed',
},
},
// Email label
{
path: '/apps/email/label/:label',
name: 'apps-email-label',
component: emailRouteComponent,
meta: {
// contentClass: 'email-application',
navActiveLink: 'apps-email',
layoutWrapperClasses: 'layout-content-height-fixed',
},
},
{
path: '/dashboards/logistics',
name: 'dashboards-logistics',
component: () => import('@/pages/apps/logistics/dashboard.vue'),
},
{
path: '/dashboards/academy',
name: 'dashboards-academy',
component: () => import('@/pages/apps/academy/dashboard.vue'),
},
{
path: '/apps/ecommerce/dashboard',
name: 'apps-ecommerce-dashboard',
component: () => import('@/pages/dashboards/ecommerce.vue'),
},
]