Skip to content

GetToken from middleware in v5 #9691

Answered by ezeparziale
ezeparziale asked this question in Help
Discussion options

You must be logged in to vote

same problem here

I resolved with this:

import { authConfig } from "@/auth.config"
import NextAuth from "next-auth"

export const { auth } = NextAuth(authConfig)

export default auth((req) => {
  const isAuthenticated = !!req.auth

 // code ...
})

export const config = {
  matcher: ["/((?!api|_next/static|_next/image|favicon.ico|auth/error).*)"],
}

Example: https://github.com/ezeparziale/quark/blob/main/src/middleware.ts

Replies: 2 comments 7 replies

Comment options

You must be logged in to vote
2 replies
@ezeparziale
Comment options

@manuelatdev
Comment options

Comment options

You must be logged in to vote
5 replies
@manuelatdev
Comment options

@AndreaBarghigiani
Comment options

@ezeparziale
Comment options

@AndreaBarghigiani
Comment options

@ezeparziale
Comment options

Answer selected by ezeparziale
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
4 participants