-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e39355b
commit 6adabab
Showing
11 changed files
with
403 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
"use client"; | ||
|
||
import { useRouter } from "next/navigation"; | ||
import { zodResolver } from "@hookform/resolvers/zod"; | ||
import { signIn } from "next-auth/react"; | ||
import type { SubmitHandler } from "react-hook-form"; | ||
import { FormProvider, useForm } from "react-hook-form"; | ||
import { toast } from "react-toastify"; | ||
import * as z from "zod"; | ||
|
||
import Button from "./button"; | ||
import Field from "./form/Field"; | ||
|
||
/* Local constants & types | ||
============================================================================= */ | ||
export type FormData = z.infer<typeof schemaValidation>; | ||
|
||
const schemaValidation = z.object({ | ||
email: z.string(), | ||
password: z.string(), | ||
}); | ||
|
||
const CredentialAuth = () => { | ||
const router = useRouter(); | ||
const methods = useForm<FormData>({ | ||
resolver: zodResolver(schemaValidation), | ||
defaultValues: { | ||
email: "", | ||
password: "", | ||
}, | ||
}); | ||
|
||
const onSubmit: SubmitHandler<FormData> = async (data: FormData) => { | ||
try { | ||
const response = await signIn("credentials", { | ||
...data, | ||
redirect: false, | ||
}); | ||
|
||
console.log({ response }); | ||
if (!response?.error) { | ||
router.push("/workspaces"); | ||
router.refresh(); | ||
} | ||
} catch (error) { | ||
console.error(error); | ||
toast.error("Invalid email or password"); | ||
} | ||
}; | ||
|
||
return ( | ||
<form | ||
method="post" | ||
className="flex w-full flex-col gap-4" | ||
onSubmit={methods.handleSubmit(onSubmit)} | ||
> | ||
<FormProvider {...methods}> | ||
<Field label="Email:" name="email" type="email" /> | ||
<Field label="Password:" name="password" type="password" /> | ||
|
||
<Button type="submit" variant="secondary"> | ||
Sign In | ||
</Button> | ||
</FormProvider> | ||
</form> | ||
); | ||
}; | ||
|
||
export default CredentialAuth; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.