on below my code for API route
export const POST = async (req: NextRequest) => {
...
try {
const { email, name, password } = await req.json();
console.info(email, name, password);
const existingUser = await prismadb.user.findUnique({
where: {
email,
},
});
if (existingUser) {
return NextResponse.json({ status: 422, error: "Email taken" });
}
const hashedPassword = await bcrypt.hash(password, 12);
const user = await prismadb.user.create({
data: {
email,
name,
hashedPassword,
image: "",
emailVerified: new Date(),
},
});
...
};
on below my code for schema.prisma
model User{
..
email String? @unique
...
}
i was defined @unique on email, but still get error
✓ Compiled /api/register/route in 468ms (332 modules)
[email protected] test 123
PrismaClientKnownRequestError:
Invalid prisma.user.findUnique()
invocation:
how i can fix this problem? please help
Note that because you added unique modifier there is no possibility to make it optional. IOW write it like that
You can refer to this documentation.