Laravel-based OAuth/IAM service with Passport, Vue 3 frontend, and Docker Compose setup for local and production deployment. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
97 lines
2.3 KiB
TypeScript
97 lines
2.3 KiB
TypeScript
import { createRouter, createWebHistory } from 'vue-router';
|
|
import { useAuthStore } from '../stores/auth';
|
|
|
|
declare module 'vue-router' {
|
|
interface RouteMeta {
|
|
requiresAuth?: boolean;
|
|
requiresAdmin?: boolean;
|
|
guestOnly?: boolean;
|
|
}
|
|
}
|
|
|
|
const routes = [
|
|
{
|
|
path: '/',
|
|
name: 'dashboard',
|
|
component: () => import('../pages/Dashboard.vue'),
|
|
meta: { requiresAuth: true },
|
|
},
|
|
{
|
|
path: '/login',
|
|
name: 'login',
|
|
component: () => import('../pages/Login.vue'),
|
|
meta: { guestOnly: true },
|
|
},
|
|
{
|
|
path: '/register',
|
|
name: 'register',
|
|
component: () => import('../pages/Register.vue'),
|
|
meta: { guestOnly: true },
|
|
},
|
|
{
|
|
path: '/clients',
|
|
name: 'clients',
|
|
component: () => import('../pages/Clients.vue'),
|
|
meta: { requiresAuth: true },
|
|
},
|
|
{
|
|
path: '/tokens',
|
|
name: 'tokens',
|
|
component: () => import('../pages/Tokens.vue'),
|
|
meta: { requiresAuth: true },
|
|
},
|
|
{
|
|
path: '/authorized-apps',
|
|
name: 'authorized-apps',
|
|
component: () => import('../pages/AuthorizedApps.vue'),
|
|
meta: { requiresAuth: true },
|
|
},
|
|
{
|
|
path: '/oauth/authorize',
|
|
name: 'oauth-authorize',
|
|
component: () => import('../pages/Authorize.vue'),
|
|
meta: { requiresAuth: true },
|
|
},
|
|
{
|
|
path: '/admin/users',
|
|
name: 'admin-users',
|
|
component: () => import('../pages/admin/Users.vue'),
|
|
meta: { requiresAuth: true, requiresAdmin: true },
|
|
},
|
|
{
|
|
path: '/admin/analytics',
|
|
name: 'admin-analytics',
|
|
component: () => import('../pages/admin/Analytics.vue'),
|
|
meta: { requiresAuth: true, requiresAdmin: true },
|
|
},
|
|
];
|
|
|
|
const router = createRouter({
|
|
history: createWebHistory(),
|
|
routes,
|
|
});
|
|
|
|
router.beforeEach(async (to) => {
|
|
const auth = useAuthStore();
|
|
|
|
if (!auth.checked) {
|
|
await auth.fetchUser();
|
|
}
|
|
|
|
if (to.meta.requiresAuth && !auth.isAuthenticated) {
|
|
return { name: 'login', query: { redirect: to.fullPath } };
|
|
}
|
|
|
|
if (to.meta.requiresAdmin && !auth.isAdmin) {
|
|
return { name: 'dashboard' };
|
|
}
|
|
|
|
if (to.meta.guestOnly && auth.isAuthenticated) {
|
|
return { name: 'dashboard' };
|
|
}
|
|
|
|
return true;
|
|
});
|
|
|
|
export default router;
|