import { withAuth } from "next-auth/middleware";
import { NextRequest, NextResponse } from "next/server";

export default withAuth(
  // `withAuth` augments your `Request` with the user's token.
  async function middleware(req: NextRequest) {
    console.log("middleware Started");
    console.log("req.url", req.url);
    console.log("req.nextUrl.pathname", req.nextUrl.pathname);
    
    const requestHeaders = new Headers(req.headers);
    requestHeaders.set('x-url', req.url);

 

    return NextResponse.next({
      request: {
        headers: requestHeaders,
      }
    });
  },
  {
    callbacks: {
      authorized: ({ token, req }) => {
        return !!token;
      },
    },
  }
);

export const config = {
  matcher: [
    '/',
    '/((?!api|_next/static|_next/image|favicon.ico|verify/logininfo|test|auth/signin).*)',
  ],
};
