11import  {  NextResponse  }  from  'next/server' 
22import  type  {  NextRequest  }  from  'next/server' 
3+ import  {  getAppSession ,  validateAppSession  }  from  './lib/session' 
34
45export  async  function  middleware ( request : NextRequest )  { 
56  const  pathname  =  request . nextUrl . pathname 
@@ -9,28 +10,22 @@ export async function middleware(request: NextRequest) {
910    pathname . startsWith ( '/images/' )  ||  // Static images 
1011    pathname . startsWith ( '/api/' )  ||  // API routes (handled separately) 
1112    pathname . startsWith ( '/_next/' )  ||  // Next.js internals 
12-     pathname . startsWith ( '/workshops' )  ||  // TODO: Add proper auth for workshops 
1313    pathname  ===  '/login'  ||  // Allow access to login page 
1414    pathname  ===  '/favicon.ico' 
1515  )  { 
1616    return  NextResponse . next ( ) 
1717  } 
1818
19-   // Check authentication status by calling  the auth API  
19+   // Check authentication status by checking  the session cookie  
2020  let  isAuthenticated  =  false  // Default to false 
2121  try  { 
22-     const  response  =  await  fetch ( new  URL ( '/api/auth' ,  request . url ) ,  { 
23-       method : 'GET' , 
24-       headers : request . headers , 
25-       credentials : 'include' , 
26-     } ) 
27-     const  data  =  await  response . json ( ) 
28-     if  ( data . authenticated )  { 
29-       isAuthenticated  =  true 
30-     } 
22+     // Works, but we can't assume that the presence of the cookie means valid session 
23+     isAuthenticated  =  request . cookies . get ( 'app-session' ) ?true :false 
24+ 
25+     // Does not work (document is not defined ?!?!) 
26+     // isAuthenticated = await validateAppSession(await getAppSession()) 
3127  }  catch  ( error )  { 
3228    console . error ( 'Error checking authentication:' ,  error ) 
33-     isAuthenticated  =  false 
3429  } 
3530
3631  // If not authenticated, redirect to login page with "from" parameter 
0 commit comments