How to implement lazy initialization of authjs (v5 beta) config in nextjs 14 without encountering the error Error: The Middleware "/src/middleware" must export a middleware or a default function?
My middleware:
import { auth } from "@/auth"
export default auth((req) => {
// my custom logic here
})
And my auth config file has this code:
import NextAuth from "next-auth"
import GitHub from "next-auth/providers/github"
export const { handlers, auth } = NextAuth(req => {
if (req) {
console.log(req) // I do something with the request's custom cookie
}
return { providers: [ GitHub ] }
})
If I go with the static method, it works but I lose the access to request req as I have to access a custom cookie in the NextAuth() and do something with it.