This work for me:
Try to put the logic such as AuthOptions at the different file example
/src/auth.ts
export const { handlers, signIn, signOut, auth } = NextAuth({})
/src/app/api/auth/[...nextauth]/route.ts
import { handlers } from "@/auth"
export const { GET, POST } = handlers