my website using mongodb and vercel doesnt work
Unanswered
Masai Lion posted this in #help-forum
Masai LionOP
help please
17 Replies
Masai LionOP
@tafutada777
it seems like OAuth provider error. do you use Auth.js and OAuth like Google?
Masai LionOP
nop
import { PrismaAdapter } from "@next-auth/prisma-adapter";
import NextAuth, { AuthOptions } from "next-auth";
import prisma from '../../../app/(autre)/libs/prismadb'
import CredentialsProvider from 'next-auth/providers/credentials'
import bcrypt from 'bcrypt'
export const authOptions: AuthOptions = {
adapter: PrismaAdapter(prisma),
providers: [
CredentialsProvider({
credentials: {
name: {label: 'name', value: 'text'},
password: {label: 'password', value: 'password'},
},
async authorize(credentials) {
if (!credentials?.name || !credentials?.password) {
throw new Error("invalid credentials")
}
const user = await prisma.user.findUnique({
where: {name: credentials.name}
});
if (!user || !user.hashedPassword) {
throw new Error("invalid credentials")
}
const isCorrectPassword = await bcrypt.compare(
credentials.password,
user.hashedPassword
)
if (!isCorrectPassword) {
throw new Error("invalid credentials")
}
return user
}
})
],
pages: {
signIn: '/'
},
debug: process.env.NODE_ENV === "development",
session: {
strategy: 'jwt'
},
secret: process.env.NEXTAUTH_SECRET,
}
export default NextAuth(authOptions)ah okay. did you enable prisma debug log?
@tafutada777 ah okay. did you enable prisma debug log?
Masai LionOP
its an extension ?
Masai LionOP
i have aready this
import { PrismaClient } from '@prisma/client'
declare global {
var prisma: PrismaClient | undefined
}
const client = globalThis.prisma || new PrismaClient()
if (process.env.NODE_ENV !== 'production') globalThis.prisma = client
export default client
declare global {
var prisma: PrismaClient | undefined
}
const client = globalThis.prisma || new PrismaClient()
if (process.env.NODE_ENV !== 'production') globalThis.prisma = client
export default client
import { PrismaClient } from '@prisma/client'
declare global {
var prisma: PrismaClient | undefined
}
const client = globalThis.prisma || new PrismaClient({
log: ['query', 'info', 'warn', 'error'],
// log: ['warn', 'error'],
})
if (process.env.NODE_ENV !== 'production') globalThis.prisma = client
export default client
like this
declare global {
var prisma: PrismaClient | undefined
}
const client = globalThis.prisma || new PrismaClient({
log: ['query', 'info', 'warn', 'error'],
// log: ['warn', 'error'],
})
if (process.env.NODE_ENV !== 'production') globalThis.prisma = client
export default client
like this
most probably, async authorize(credentials) throws an exception. you wanna add console.log() to see where it failed. make sure if user is fetched or not.
in local yes
put in vercel no
Masai LionOP
made it