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
email String @unique
You can refer to this documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With