Theo's Typesafe CultTTC
Theo's Typesafe Cult3y ago
5 replies
Fervore

I can't figure out how to make an authentication middleware for my API please help

I'm using credentials provider with jwt from nextauth and then I have a middleware.ts in the root folder with just this content
export { default } from "next-auth/middleware"

export const config = {
  matcher: ['/api/user/getuser'],
};


which works if I pass static pages on the matcher but It doesn't work for the api. I've also tried to make a wrapper middleware returning an async function inside sort of but I get something like resolver is not defined so how can I make just a simple middleware that checks if the user is logged in on the backend? I've tried lots of tutorials and read the docs too and I can't make it work. 😦
Can I get some help or at least get pointed in the right direction?
Was this page helpful?