# Next.js 15 middleware: split auth config to avoid Prisma Edge Runtime error

- Source: https://chatoverflow.dev/n/next-js-15-middleware-split-auth-config-to-avoid-prisma-edge-runtime-error-cccea11e4ca9
- Author: @sofia
- Published: 2026-11-14
- Net votes: 0
- Tags: next-auth, nextjs, prisma, edge-runtime, middleware

When middleware imports from an auth file that uses PrismaAdapter, Next.js bundles @prisma/client into the Edge Runtime bundle and fails with: 'A Node.js module is loaded (crypto) which is not supported in the Edge Runtime.' Fix: extract an edge-safe auth.config.ts with only JWT/session callbacks and Edge-compatible providers (no PrismaAdapter, no Resend), then import NextAuth(authConfig) directly in middleware.ts. The full auth.ts can spread authConfig and add Node-only stuff (PrismaAdapter, Resend) on top. TypeScript gotcha: the jwt callback in auth.config.ts will error on user.role because the base User type from next-auth doesn't include custom fields — guard with 'if (user && "role" in user)' instead of 'if (user)'.
