middleware test

This commit is contained in:
2026-01-03 22:05:00 +01:00
parent c589b3c3fe
commit bc7cb2e20a
7 changed files with 680 additions and 78 deletions

View File

@@ -250,10 +250,21 @@ export const routeMatchers = {
*/
isPublic(path: string): boolean {
const publicPatterns = this.getPublicPatterns();
// Check exact matches
if (publicPatterns.includes(path)) return true;
// Treat top-level detail pages as public (e2e relies on this)
// Examples: /leagues/:id, /races/:id, /drivers/:id, /teams/:id
const segments = path.split('/').filter(Boolean);
if (segments.length === 2) {
const [group, slug] = segments;
if (group === 'leagues' && slug !== 'create') return true;
if (group === 'races') return true;
if (group === 'drivers') return true;
if (group === 'teams') return true;
}
// Check parameterized patterns
return publicPatterns.some(pattern => {
if (pattern.includes('[')) {
@@ -277,7 +288,9 @@ export const routeMatchers = {
*/
requiresRole(path: string): string[] | null {
if (this.isInGroup(path, 'admin')) {
return ['owner', 'admin'];
// Website session roles come from the API and are more specific than just "admin".
// Keep "admin"/"owner" for backwards compatibility.
return ['admin', 'owner', 'league-admin', 'league-steward', 'league-owner', 'system-owner', 'super-admin'];
}
if (this.isInGroup(path, 'sponsor')) {
return ['sponsor'];
@@ -301,7 +314,7 @@ export const routeMatchers = {
export function buildPath(
routeName: string,
params: Record<string, string> = {},
locale?: string
_locale?: string
): string {
// This is a placeholder for future i18n implementation
// For now, it just builds the path using the route config
@@ -318,10 +331,11 @@ export function buildPath(
if (typeof route === 'function') {
const paramKeys = Object.keys(params);
if (paramKeys.length === 0) {
const paramKey = paramKeys[0];
if (!paramKey) {
throw new Error(`Route ${routeName} requires parameters`);
}
return route(params[paramKeys[0]]);
return route(params[paramKey]);
}
return route as string;