feat(auth): update user lookup to support name or email in authentication

When testing api endpoints make sure to login with a real user (not with the dev hardcoded user) by either registering one with a password other than "password" or setting DISABLE_AUTH_TEST_USER to "true" (`DISABLE_AUTH_TEST_USER=true yarn dev`)
This commit is contained in:
Dominik 2025-06-14 11:45:14 +02:00
parent ae8c4da25d
commit 637f33d0ff
Signed by: dominik
GPG key ID: 06A4003FC5049644

View file

@ -25,7 +25,7 @@ const providers: Provider[] = [
Credentials({ Credentials({
credentials: { password: { label: 'Password', type: 'password' } }, credentials: { password: { label: 'Password', type: 'password' } },
async authorize(c) { async authorize(c) {
if (process.env.NODE_ENV === 'development' && c.password === 'password') if (process.env.NODE_ENV === 'development' && process.env.DISABLE_AUTH_TEST_USER !== 'true' && c.password === 'password')
return { return {
id: 'test', id: 'test',
name: 'Test User', name: 'Test User',
@ -37,7 +37,7 @@ const providers: Provider[] = [
const { email, password } = await loginSchema.parseAsync(c); const { email, password } = await loginSchema.parseAsync(c);
const user = await prisma.user.findFirst({ const user = await prisma.user.findFirst({
where: { email }, where: { OR: [{ email }, { name: email }] },
include: { accounts: true }, include: { accounts: true },
}); });