K
Kinde•5mo ago
theo

Middleware based protection not working

in my middleware.ts, i have the following code
import { withAuth } from "@kinde-oss/kinde-auth-nextjs/middleware"

export default withAuth(
async function middleware(req) {
console.log("auth", req.kindeAuth)
},
{
isReturnToCurrentPage: false,
loginPage: "/signin",
isAuthorized: ({token}) => {
return token.permissions.includes("admin:admin");
}
}
)

export const config = {
matcher: [
"/admin",
"/about",
]
}
import { withAuth } from "@kinde-oss/kinde-auth-nextjs/middleware"

export default withAuth(
async function middleware(req) {
console.log("auth", req.kindeAuth)
},
{
isReturnToCurrentPage: false,
loginPage: "/signin",
isAuthorized: ({token}) => {
return token.permissions.includes("admin:admin");
}
}
)

export const config = {
matcher: [
"/admin",
"/about",
]
}
however, it simply doesnt protect any routes, while page based protection does work, however i want to avoid using that
4 Replies
CB_Kinde
CB_Kinde•5mo ago
Hi Theo. I'll check with one of our team who is experienced with Next.js and get back to you.
Peteswah
Peteswah•5mo ago
does the console log pop up in your terminal? Just checking that the middleware is running 1. check the middleware is running -> you can remove withAuth and then just have it be a log to see if it is running on the /admin and /about routes. If not running then you have to move the file into the root directory 2. If it is running, then it could be a bug because your code looks good. Raise a quick issue and I'll jump in and I'll try and resolve it 😄
theo
theoOP•5mo ago
i had the middleware in app/ rather than src/ im so sorry thank you!!!!
Daniel_Kinde
Daniel_Kinde•5mo ago
Great, let us know if you need any further help
Want results from more Discord servers?
Add your server