(globalThis.TURBOPACK || (globalThis.TURBOPACK = [])).push(["chunks/[root-of-the-server]__5a7ed556._.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]/C:/Users/Olatunde Sleek/Desktop/cbt-frontend/src/middleware.ts [middleware-edge] (ecmascript)", ((__turbopack_context__) => {
"use strict";

__turbopack_context__.s([
    "config",
    ()=>config,
    "middleware",
    ()=>middleware
]);
var __TURBOPACK__imported__module__$5b$project$5d2f$C$3a2f$Users$2f$Olatunde__Sleek$2f$Desktop$2f$cbt$2d$frontend$2f$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]/C:/Users/Olatunde Sleek/Desktop/cbt-frontend/node_modules/next/dist/esm/api/server.js [middleware-edge] (ecmascript) <locals>");
var __TURBOPACK__imported__module__$5b$project$5d2f$C$3a2f$Users$2f$Olatunde__Sleek$2f$Desktop$2f$cbt$2d$frontend$2f$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]/C:/Users/Olatunde Sleek/Desktop/cbt-frontend/node_modules/next/dist/esm/server/web/exports/index.js [middleware-edge] (ecmascript)");
;
// Paths that don't require authentication
const publicPaths = [
    "/" /* "/admin/login", */ 
];
async function middleware(request) {
    const { pathname } = request.nextUrl;
    // Check for auth token
    const authToken = request.cookies.get('token');
    //check user roles
    const role = request.cookies.get('role')?.value;
    // Allow public paths
    if (publicPaths.includes(pathname) && !authToken) {
        return __TURBOPACK__imported__module__$5b$project$5d2f$C$3a2f$Users$2f$Olatunde__Sleek$2f$Desktop$2f$cbt$2d$frontend$2f$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 (!authToken) {
        // Redirect to appropriate login page based on path
        return __TURBOPACK__imported__module__$5b$project$5d2f$C$3a2f$Users$2f$Olatunde__Sleek$2f$Desktop$2f$cbt$2d$frontend$2f$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(new URL('/', request.url));
    }
    // try {
    // Verify role for admin routes
    if (pathname.startsWith('/admin')) {
        if (role !== 'admin' && role !== 'teacher') {
            return __TURBOPACK__imported__module__$5b$project$5d2f$C$3a2f$Users$2f$Olatunde__Sleek$2f$Desktop$2f$cbt$2d$frontend$2f$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(new URL('/dashboard', request.url));
        }
    }
    // Student trying to access dashboard while logged in
    if (pathname === '/' && authToken && role === 'student') {
        return __TURBOPACK__imported__module__$5b$project$5d2f$C$3a2f$Users$2f$Olatunde__Sleek$2f$Desktop$2f$cbt$2d$frontend$2f$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(new URL('/dashboard', request.url));
    }
    // Admin/Teacher trying to access login while logged in
    if (pathname === '/' && authToken && (role === 'admin' || role === 'teacher')) {
        return __TURBOPACK__imported__module__$5b$project$5d2f$C$3a2f$Users$2f$Olatunde__Sleek$2f$Desktop$2f$cbt$2d$frontend$2f$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(new URL('/admin/dashboard', request.url));
    }
    if (!pathname.startsWith('/admin') && authToken && (role === 'admin' || role === 'teacher')) {
        return __TURBOPACK__imported__module__$5b$project$5d2f$C$3a2f$Users$2f$Olatunde__Sleek$2f$Desktop$2f$cbt$2d$frontend$2f$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(new URL(`/admin/${pathname}`, request.url));
    }
    return __TURBOPACK__imported__module__$5b$project$5d2f$C$3a2f$Users$2f$Olatunde__Sleek$2f$Desktop$2f$cbt$2d$frontend$2f$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 = {
    /*
   * Match all request paths except:
   * - _next/static (static files)
   * - _next/image (image optimization files)
   * - favicon.ico (favicon file)
   * - images folder
   * - public assets
   */ matcher: [
        '/((?!api|_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp|ico)$).*)'
    ]
};
}),
]);

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