(globalThis.TURBOPACK || (globalThis.TURBOPACK = [])).push(["chunks/[root-of-the-server]__2a3b70b7._.js",
"[externals]/node:buffer [external] (node:buffer, cjs)", ((__turbopack_context__, module, exports) => {

const mod = __turbopack_context__.x("node:buffer", () => require("node:buffer"));

module.exports = mod;
}),
"[externals]/node:async_hooks [external] (node:async_hooks, cjs)", ((__turbopack_context__, module, exports) => {

const mod = __turbopack_context__.x("node:async_hooks", () => require("node:async_hooks"));

module.exports = mod;
}),
"[project]/src/config/routes.ts [middleware-edge] (ecmascript)", ((__turbopack_context__) => {
"use strict";

// Route protection configuration
__turbopack_context__.s([
    "getRouteConfig",
    ()=>getRouteConfig,
    "isAuthRoute",
    ()=>isAuthRoute,
    "isProtectedRoute",
    ()=>isProtectedRoute,
    "isPublicRoute",
    ()=>isPublicRoute,
    "matchesPattern",
    ()=>matchesPattern,
    "routeConfigs",
    ()=>routeConfigs
]);
const routeConfigs = [
    // Public routes - no authentication required
    {
        pattern: "/",
        type: "public"
    },
    {
        pattern: "/about",
        type: "public"
    },
    {
        pattern: "/contact",
        type: "public"
    },
    {
        pattern: "/help",
        type: "public"
    },
    {
        pattern: "/privacy",
        type: "public"
    },
    {
        pattern: "/terms",
        type: "public"
    },
    // Auth routes - redirect authenticated users away
    {
        pattern: "/auth/login",
        type: "auth",
        redirectTo: "/dashboard"
    },
    {
        pattern: "/auth/login/callback",
        type: "public"
    },
    {
        pattern: "/auth/register",
        type: "auth",
        redirectTo: "/dashboard"
    },
    // Protected routes - require authentication
    {
        pattern: "/dashboard",
        type: "protected"
    },
    {
        pattern: "/dashboard/*",
        type: "protected"
    },
    {
        pattern: "/profile",
        type: "protected"
    },
    {
        pattern: "/settings",
        type: "protected"
    },
    {
        pattern: "/admin/*",
        type: "protected",
        roles: [
            "admin"
        ]
    }
];
function matchesPattern(pathname, pattern) {
    if (pattern.includes("*")) {
        const regex = new RegExp("^" + pattern.replace(/\*/g, ".*") + "$");
        return regex.test(pathname);
    }
    return pathname === pattern || pathname.startsWith(pattern + "/");
}
function getRouteConfig(pathname) {
    return routeConfigs.find((config)=>matchesPattern(pathname, config.pattern));
}
function isProtectedRoute(pathname) {
    return routeConfigs.some((config)=>config.type === "protected" && matchesPattern(pathname, config.pattern));
}
function isAuthRoute(pathname) {
    return routeConfigs.some((config)=>config.type === "auth" && matchesPattern(pathname, config.pattern));
}
function isPublicRoute(pathname) {
    return routeConfigs.some((config)=>config.type === "public" && matchesPattern(pathname, config.pattern));
}
}),
"[project]/src/middleware.ts [middleware-edge] (ecmascript)", ((__turbopack_context__) => {
"use strict";

__turbopack_context__.s([
    "config",
    ()=>config,
    "middleware",
    ()=>middleware
]);
var __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$dist$2f$esm$2f$api$2f$server$2e$js__$5b$middleware$2d$edge$5d$__$28$ecmascript$29$__$3c$locals$3e$__ = __turbopack_context__.i("[project]/node_modules/next/dist/esm/api/server.js [middleware-edge] (ecmascript) <locals>");
var __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$dist$2f$esm$2f$server$2f$web$2f$exports$2f$index$2e$js__$5b$middleware$2d$edge$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/node_modules/next/dist/esm/server/web/exports/index.js [middleware-edge] (ecmascript)");
var __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$config$2f$routes$2e$ts__$5b$middleware$2d$edge$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/src/config/routes.ts [middleware-edge] (ecmascript)");
;
;
function middleware(request) {
    const { pathname } = request.nextUrl;
    // Skip middleware for certain paths
    if (pathname.startsWith("/_next") || pathname.startsWith("/api") || pathname.startsWith("/favicon") || pathname.includes(".")) {
        return __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$dist$2f$esm$2f$server$2f$web$2f$exports$2f$index$2e$js__$5b$middleware$2d$edge$5d$__$28$ecmascript$29$__["NextResponse"].next();
    }
    // Get authentication token from cookies
    const token = request.cookies.get("ksso_token")?.value;
    const isAuthenticated = !!token;
    // Get route configuration for current path
    const routeConfig = (0, __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$config$2f$routes$2e$ts__$5b$middleware$2d$edge$5d$__$28$ecmascript$29$__["getRouteConfig"])(pathname);
    // If no specific config found, default behavior based on route type detection
    if (!routeConfig) {
        // Check using helper functions for broader pattern matching
        if ((0, __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$config$2f$routes$2e$ts__$5b$middleware$2d$edge$5d$__$28$ecmascript$29$__["isPublicRoute"])(pathname)) {
            return __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$dist$2f$esm$2f$server$2f$web$2f$exports$2f$index$2e$js__$5b$middleware$2d$edge$5d$__$28$ecmascript$29$__["NextResponse"].next();
        }
        if ((0, __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$config$2f$routes$2e$ts__$5b$middleware$2d$edge$5d$__$28$ecmascript$29$__["isAuthRoute"])(pathname)) {
            if (isAuthenticated) {
                const dashboardUrl = new URL("/dashboard", request.url);
                return __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$dist$2f$esm$2f$server$2f$web$2f$exports$2f$index$2e$js__$5b$middleware$2d$edge$5d$__$28$ecmascript$29$__["NextResponse"].redirect(dashboardUrl);
            }
            return __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$dist$2f$esm$2f$server$2f$web$2f$exports$2f$index$2e$js__$5b$middleware$2d$edge$5d$__$28$ecmascript$29$__["NextResponse"].next();
        }
        if ((0, __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$config$2f$routes$2e$ts__$5b$middleware$2d$edge$5d$__$28$ecmascript$29$__["isProtectedRoute"])(pathname)) {
            if (!isAuthenticated) {
                const loginUrl = new URL("/auth/login", request.url);
                loginUrl.searchParams.set("redirect", pathname);
                return __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$dist$2f$esm$2f$server$2f$web$2f$exports$2f$index$2e$js__$5b$middleware$2d$edge$5d$__$28$ecmascript$29$__["NextResponse"].redirect(loginUrl);
            }
            return __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$dist$2f$esm$2f$server$2f$web$2f$exports$2f$index$2e$js__$5b$middleware$2d$edge$5d$__$28$ecmascript$29$__["NextResponse"].next();
        }
        // Default: allow access (treat as public)
        return __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$dist$2f$esm$2f$server$2f$web$2f$exports$2f$index$2e$js__$5b$middleware$2d$edge$5d$__$28$ecmascript$29$__["NextResponse"].next();
    }
    // Handle based on route configuration
    switch(routeConfig.type){
        case "public":
            return __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$dist$2f$esm$2f$server$2f$web$2f$exports$2f$index$2e$js__$5b$middleware$2d$edge$5d$__$28$ecmascript$29$__["NextResponse"].next();
        case "auth":
            if (isAuthenticated) {
                const redirectTo = routeConfig.redirectTo || "/dashboard";
                const redirectUrl = new URL(redirectTo, request.url);
                return __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$dist$2f$esm$2f$server$2f$web$2f$exports$2f$index$2e$js__$5b$middleware$2d$edge$5d$__$28$ecmascript$29$__["NextResponse"].redirect(redirectUrl);
            }
            return __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$dist$2f$esm$2f$server$2f$web$2f$exports$2f$index$2e$js__$5b$middleware$2d$edge$5d$__$28$ecmascript$29$__["NextResponse"].next();
        case "protected":
            if (!isAuthenticated) {
                const loginUrl = new URL("/auth/login", request.url);
                loginUrl.searchParams.set("redirect", pathname);
                return __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$dist$2f$esm$2f$server$2f$web$2f$exports$2f$index$2e$js__$5b$middleware$2d$edge$5d$__$28$ecmascript$29$__["NextResponse"].redirect(loginUrl);
            }
            // Future: Role-based access control
            if (routeConfig.roles && routeConfig.roles.length > 0) {
            // TODO: Implement role checking when user roles are available
            // For now, just allow access if authenticated
            }
            return __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$dist$2f$esm$2f$server$2f$web$2f$exports$2f$index$2e$js__$5b$middleware$2d$edge$5d$__$28$ecmascript$29$__["NextResponse"].next();
        default:
            return __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$dist$2f$esm$2f$server$2f$web$2f$exports$2f$index$2e$js__$5b$middleware$2d$edge$5d$__$28$ecmascript$29$__["NextResponse"].next();
    }
}
const config = {
    matcher: [
        /*
     * Match all request paths except for the ones starting with:
     * - api (API routes)
     * - _next/static (static files)
     * - _next/image (image optimization files)
     * - favicon.ico (favicon file)
     * - files with extensions (images, etc.)
     */ "/((?!api|_next/static|_next/image|favicon.ico|.*\\..*).*)"
    ]
};
}),
]);

//# sourceMappingURL=%5Broot-of-the-server%5D__2a3b70b7._.js.map