feat: implement credentials login

implements the credentials login functionality
This commit is contained in:
Dominik 2025-05-28 13:08:07 +02:00 committed by Dominik
parent 210bd132cc
commit 4e87c11ec3
10 changed files with 522 additions and 115 deletions

27
src/lib/auth/login.ts Normal file
View file

@ -0,0 +1,27 @@
'use server';
import { z } from 'zod';
import { loginSchema } from '@/lib/validation/user';
import { signIn } from '@/auth';
export async function loginAction(data: z.infer<typeof loginSchema>) {
try {
await signIn('credentials', {
...data,
redirect: false,
});
return {
error: undefined,
};
} catch (error: unknown) {
if (error instanceof Error) {
return {
error: error.message.toString(),
};
}
return {
error: 'An unknown error occurred.',
};
}
}