Here is my code snippet for the 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(),
},
});
...
};
Below is my schema.prisma code:
model User{
..
email String? @unique
...
}
I have defined @unique
on the email field, but I am still encountering an error.
✓ Compiled /api/register/route in 468ms (332 modules)
[email protected] test 123
PrismaClientKnownRequestError:
Invalid prisma.user.findUnique()
invocation:
Can anyone provide guidance on how to resolve this issue? Your help would be greatly appreciated.