Spaces:
Sleeping
Sleeping
File size: 2,355 Bytes
fa14516 cd4ab7b fa14516 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | /**
* Route Configuration for Protected Routes
*
* Defines which routes are public, which require authentication,
* and which require specific roles.
*/
// Public routes - no authentication required
export const publicRoutes: string[] = [
'/api/auth/github',
'/api/auth/github/callback',
'/api/health',
];
// Routes that require MAINTAINER role
export const maintainerOnlyRoutes: string[] = [
'/api/maintainer',
'/api/repositories',
];
// Routes that require CONTRIBUTOR role
export const contributorOnlyRoutes: string[] = [
'/api/contributor',
];
// Routes accessible by any authenticated user
export const authenticatedRoutes: string[] = [
'/api/auth/me',
'/api/auth/select-role',
'/api/profile',
'/api/messaging',
'/api/messages',
'/api/chat',
'/api/ai',
'/api/rag',
'/api/mentor',
'/api/badges',
'/api/user',
'/api/sync', // Both maintainers and contributors can sync
];
/**
* Check if a route is public (no auth required)
*/
export function isPublicRoute(pathname: string): boolean {
return publicRoutes.some(route =>
pathname === route || pathname.startsWith(route + '/')
);
}
/**
* Check if a route requires MAINTAINER role
*/
export function isMaintainerRoute(pathname: string): boolean {
return maintainerOnlyRoutes.some(route =>
pathname === route || pathname.startsWith(route + '/')
);
}
/**
* Check if a route requires CONTRIBUTOR role
*/
export function isContributorRoute(pathname: string): boolean {
return contributorOnlyRoutes.some(route =>
pathname === route || pathname.startsWith(route + '/')
);
}
/**
* Check if a route requires any authentication
*/
export function requiresAuth(pathname: string): boolean {
// If it's public, no auth required
if (isPublicRoute(pathname)) {
return false;
}
// All API routes require auth by default
if (pathname.startsWith('/api/')) {
return true;
}
return false;
}
/**
* Get required role for a route (null if any authenticated user can access)
*/
export function getRequiredRole(pathname: string): 'MAINTAINER' | 'CONTRIBUTOR' | null {
if (isMaintainerRoute(pathname)) {
return 'MAINTAINER';
}
if (isContributorRoute(pathname)) {
return 'CONTRIBUTOR';
}
return null;
}
|