Order
PPrisma
•Created by Order on 5/16/2024 in #help-and-questions
I want to find a user with either email or username but I'm getting a typescript error
I'm setting up nextauth in nextjs with prisma and postgres and I want the user to be able to interchangably log in with either email or password. So I set this up:
async authorize(credentials) {
const user = await prisma.user.findUnique({
where: {
OR: [
{
email: credentials?.username,
},
{
username: credentials?.username,
},
],
},
});
However I'm getting a type error on my where Type '{ OR: ({ email: string | undefined; } | { username: string | undefined; })[]; }' is not assignable to type 'UserWhereUniqueInput'.
Type '{ OR: ({ email: string | undefined; } | { username: string | undefined; })[]; }' is not assignable to type '{ id: string; email: string; username: string; } & { id?: string | undefined; username?: string | undefined; email?: string | undefined; AND?: UserWhereInput | UserWhereInput[] | undefined; ... 10 more ...; sessions?: SessionListRelationFilter | undefined; }'.
Type '{ OR: ({ email: string | undefined; } | { username: string | undefined; })[]; }' is missing the following properties from type '{ id: string; email: string; username: string; }': id, email, usernamets(2322)
index.d.ts(3896, 5): The expected type comes from property 'where' which is declared here on type '{ select?: UserSelect<DefaultArgs> | null | undefined; include?: UserInclude<DefaultArgs> | null | undefined; where: UserWhereUniqueInput; }'
(property) where: Prisma.UserWhereUniqueInput
.
I'm pretty sure I'm doing something wrong but I don't know what. Both my username and email fields in my user model are marked as unique.3 replies