Files
var-monorepo/apps/hub/app/(auth)/login/_components/Login.tsx
2025-01-27 01:45:03 +01:00

47 lines
1.2 KiB
TypeScript

'use client';
import { zodResolver } from '@hookform/resolvers/zod';
import { signIn } from 'next-auth/react';
import { useForm } from 'react-hook-form';
import { z } from 'zod';
export const Login = () => {
const schema = z.object({
email: z.string().email(),
password: z.string().min(6),
});
type schemaType = z.infer<typeof schema>;
const form = useForm<schemaType>({
resolver: zodResolver(schema),
});
console.log(form.formState.errors);
return (
<form
className="flex flex-col space-y-4 "
onSubmit={form.handleSubmit(async () => {
const data = await signIn('credentials', {
redirect: false,
email: form.getValues('email'),
password: form.getValues('password'),
});
console.log(data);
})}
>
<input
{...form.register('email')}
placeholder="Email"
className="border border-gray-300 rounded-md p-2"
/>
<input
{...form.register('password')}
placeholder="Password"
className="border border-gray-300 rounded-md p-2"
/>
<button type="submit" className="bg-blue-500 text-white rounded-md p-2">
Login
</button>
</form>
);
};