import{NextResponse}from'next/server';importtype{NextRequest}from'next/server';import{getToken}from'next-auth/jwt';exportasyncfunctionmiddleware(request:NextRequest){consttoken=awaitgetToken({req:request,secret:process.env.NEXT_AUTH_SECRET});const{pathname}=request.nextUrl;// If the user is logged in and they try to access /signin , /, redirect them away.constunAuthorizedRouteOnly=["/signin","/"]if (token&&unAuthorizedRouteOnly.includes(pathname)){returnNextResponse.redirect(newURL('/dashboard',request.url));}// If no token is found and they are not already on /signin or /, redirect to /signin.if (!token&&!unAuthorizedRouteOnly.includes(pathname)){constsignInUrl=newURL('/signin',request.url);signInUrl.searchParams.set('callbackUrl',request.url);returnNextResponse.redirect(signInUrl);}// Allow the request to proceed if none of the above conditions are met.returnNextResponse.next();}exportconstconfig={matcher:['/((?!api|_next/static|_next/image|favicon.ico).*)'],};