P
Prisma2w ago
ppzhu

Best practice for route protection in Next.js + Auth.js + Prisma (avoiding Prisma Edge runtime issue

Hi everyone, I’m a beginner with the Next.js + Auth.js + Prisma stack and I’m stuck on route protection. I already set up GitHub login successfully (https://github.com/harley61p/nextjs-authjs-prisma-example.git). Now I want to protect certain routes, so that only logged-in users can access them. I tried using middleware.ts, but Prisma throws an error: PrismaClientValidationError: In order to run Prisma Client on edge runtime... I understand middleware runs on the Edge runtime, so Prisma can’t be used there. But what’s the recommended way to implement elegant route protection with this stack? Should I only check session/token inside middleware.ts and move DB checks to server components / API routes? Or is there a better practice? Which Discord would be best to ask this (Next.js, Prisma, or Auth.js)? Thanks a lot! 🙏
1 Reply
Prisma AI Help
You decided to hold for human wisdom. We'll chime in soon! Meanwhile, #ask-ai is there if you need a quick second opinion.

Did you find this page helpful?