182 viewsNext Amazona
0 Comments

After using middleware it says this

export { auth as middleware } from './lib/auth'

export const config = {
  matcher: [
    /*
     * Match all request paths except for the ones starting with:
     * - api (API routes)
     * - _next/static (static files)
     * - _next/image (image optimization files)
     * - favicon.ico (favicon file)
     */
    '/((?!api|_next/static|_next/image|favicon.ico).*)',
  ],
}

I think the error is that: we are importing a auth from a while which uses nextauth and middlewar cannot import modules which uses next auth.
i tried to separte the files but it alos does not work

Bassir Changed status to publish February 7, 2024

Edge Middleware runs on the Edge Runtime, a runtime built on top of the V8 JavaScript engine. The Edge Runtime provides a subset of Web APIs for you to use when creating Middleware. This lightweight API layer is built to be performant and execute code with minimal latency. When writing Middleware, you can use any of the supported APIs from the Edge Runtime.

If you follow my code on auth.ts you shouldn’t get that error.

also add ._doc to jwt function like this:

async jwt({ user, trigger, session, token }: any) {
        if (user) {
        token.user = {
        _id: user._doc._id,
        email: user._doc.email,
        name: user.\_doc.name,
        isAdmin: user._doc.isAdmin,
        }
        }
...}
Bassir Edited answer February 7, 2024
You are viewing 1 out of 1 answers, click here to view all answers.