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 â@next-auth/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(
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,
name: dbUser.name,
email: dbUser.email,
picture: dbUser.image,
};
},
async session({ session, token }) {
if (token) {
session.user = {
name: token.name,
email: 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