added Login page
This commit is contained in:
44
apps/hub/app/(auth)/login/_components/Login.tsx
Normal file
44
apps/hub/app/(auth)/login/_components/Login.tsx
Normal file
@@ -0,0 +1,44 @@
|
||||
'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),
|
||||
});
|
||||
|
||||
const form = useForm({
|
||||
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>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user