GetToken from middleware in v5 #9691
Answered
by
ezeparziale
ezeparziale
asked this question in
Help
-
I am testing version 5. // middleware.ts
import { NextResponse } from "next/server"
import type { NextFetchEvent, NextRequest } from "next/server"
import { getToken } from "next-auth/jwt"
export default async function middleware(req: NextRequest) {
const token = await getToken({ req })
const isAuthenticated = !!token
// ...
}
export const config = {
matcher: ["/((?!api|_next/static|_next/image|favicon.ico|auth/error).*)"],
} Using the I am using: Any ideas? |
Beta Was this translation helpful? Give feedback.
Answered by
ezeparziale
May 20, 2024
Replies: 2 comments 8 replies
-
Did you resolve this issue? |
Beta Was this translation helpful? Give feedback.
2 replies
-
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 |
Beta Was this translation helpful? Give feedback.
6 replies
Answer selected by
ezeparziale
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I resolved with this:
Example: https://github.com/ezeparziale/quark/blob/main/src/middleware.ts