1- // middleware.ts
2- import { NextResponse } from 'next/server'
3- import type { NextRequest } from 'next/server'
1+ import { NextResponse } from 'next/server' ;
2+ import type { NextRequest } from 'next/server' ;
43
54export function middleware ( request : NextRequest ) {
6- const { pathname } = request . nextUrl
7- const token = request . cookies . get ( 'authToken' ) ?. value
5+ const { pathname } = request . nextUrl ;
6+ const token = request . cookies . get ( 'authToken' ) ?. value ;
87
9- // Define public routes that don't need authentication
10- const publicRoutes = [ '/auth' ]
11-
12- // Check if the current path is a public route
13- const isPublicRoute = publicRoutes . includes ( pathname ) ||
14- publicRoutes . some ( route => pathname . startsWith ( route + '/' ) )
8+ // Public routes that don't require auth
9+ const publicRoutes = [ '/auth' ] ;
10+ const isPublicRoute =
11+ publicRoutes . includes ( pathname ) ||
12+ publicRoutes . some ( ( route ) => pathname . startsWith ( route + '/' ) ) ;
1513
16- // If user has no token and trying to access protected route
17- if ( ! token && ! isPublicRoute ) {
18- console . log ( `Redirecting ${ pathname } to /auth - no token` )
19- return NextResponse . redirect ( new URL ( '/auth' , request . url ) )
20- }
14+ // If no token and trying to access protected route
15+ // if (!token && !isPublicRoute) {
16+ // console.log(`Redirecting ${pathname} to /auth - no token`);
17+ // return NextResponse.redirect(new URL('/auth', request.url));
18+ // }
2119
22- // If user has token and trying to access auth page, redirect to home
23- if ( token && pathname === '/auth' ) {
24- console . log ( `Redirecting from /auth to / - user has token` )
25- return NextResponse . redirect ( new URL ( '/' , request . url ) )
26- }
27-
28- return NextResponse . next ( )
20+ return NextResponse . next ( ) ;
2921}
3022
3123export const config = {
3224 matcher : [
33- /*
34- * Match all request paths except for the ones starting with:
35- * - api (API routes)
36- * - _next/static (static files)
37- * - _next/image (image optimization files)
38- * - favicon.ico (favicon file)
39- * - public files (images, etc.)
40- */
4125 '/((?!api|_next/static|_next/image|favicon.ico|images|.*\\..*).*)' ,
4226 ] ,
43- }
27+ } ;
0 commit comments