Summary
I am using next auth for authentication. It is okay on local build. But when it is on vercel deploy production build it is throwing following error.
at 74088 (/vercel/path0/.next/server/app/api/auth/[...nextauth]/route.js:1:1513) at t (/vercel/path0/.next/server/webpack-runtime.js:1:128) at r (/vercel/path0/.next/server/app/api/auth/[...nextauth]/route.js:39:88504) at /vercel/path0/.next/server/app/api/auth/[...nextauth]/route.js:39:88531 at t.X (/vercel/path0/.next/server/webpack-runtime.js:1:1196) at /vercel/path0/.next/server/app/api/auth/[...nextauth]/route.js:39:88517 at Object.<anonymous> (/vercel/path0/.next/server/app/api/auth/[...nextauth]/route.js:39:88559) at Module._compile (node:internal/modules/cjs/loader:1358:14) { clientVersion: '5.17.0', errorCode: undefined } Build error occurred Error: Failed to collect page data for /api/auth/[...nextauth] at /vercel/path0/node_modules/next/dist/build/utils.js:1268:15 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) { type: 'Error' } Error: Command "npm run build" exited with 1
This is my api/auth/[...nextauth]/route.ts
import { authOptions } from '@/lib/auth'; import NextAuth from 'next-auth/next';
const handler = NextAuth(authOptions); export { handler as GET, handler as POST };
This is my lib/auth.ts
import { AuthOptions, getServerSession } from 'next-auth'; import CredentialsProvider from 'next-auth/providers/credentials'; import { PrismaAdapter } from '/prisma-adapter'; import { prisma } from '@/lib/prisma'; import bcrypt from 'bcrypt';
export const authOptions: AuthOptions = { adapter: PrismaAdapter(prisma), session: { strategy: 'jwt', }, secret: process.env.NEXTAUTH_SECRET, providers: [ CredentialsProvider({ name: 'credentials', credentials: { email: { label: 'email:', type: 'text', placeholder: 'your-email', }, password: { label: 'password:', type: 'password', placeholder: 'your-password', }, }, async authorize(credentials) { const user = await prisma.user.findUnique({ where: { email: credentials?.email }, });
if (!user) { throw new Error("User doesn't exist"); } const isPasswordMatch = await [bcrypt.compare](https://bcrypt.compare)( credentials?.password!, user?.password!, ); if (!isPasswordMatch) { throw new Error('Invalid Password!'); } return user; },}),],
callbacks: { async signIn() { return true; }, async jwt({ token }) { const dbUser = await prisma.user.findUnique({ where: { email: token.email! } });
if (!dbUser) { throw new Error('No user is found with this email!'); } return { id: [dbUser.id](https://dbuser.id), name: [dbUser.name](https://dbuser.name), email: [dbUser.email](https://dbuser.email), picture: dbUser.image, };},async session({ session, token }) { if (token) { session.user = { name: [token.name](https://token.name), email: [token.email](https://token.email), image: token.picture, }; } return session;},}, } satisfies AuthOptions;
export function getSession() { return getServerSession(authOptions); }
this is my .env and env variable that i put on production build
DATABASE_URL=DBURL NEXTAUTH_SECRET=3ijfdl2393djDf919 NEXTAUTH_URL=http://localhost:3000
I have tried several solution but no one solve my situation
Example
No response
Steps to Reproduce
Just deploy my app on vercel

