feat: implement credentials login
implements the credentials login functionality
This commit is contained in:
parent
210bd132cc
commit
4e87c11ec3
10 changed files with 522 additions and 115 deletions
27
src/lib/auth/login.ts
Normal file
27
src/lib/auth/login.ts
Normal 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.',
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue