-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from git-init-priyanshu/nextjs
Authentication
- Loading branch information
Showing
29 changed files
with
482 additions
and
485 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 was deleted.
Oops, something went wrong.
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,64 @@ | ||
import Link from "next/link" | ||
import { useRouter } from "next/navigation" | ||
import { useForm } from 'react-hook-form' | ||
import { z } from 'zod' | ||
|
||
import { Button } from "@/components/ui/button" | ||
import { Input } from "@/components/ui/input" | ||
import { Label } from "@/components/ui/label" | ||
|
||
import { SigninAction } from "../../actions" | ||
import { signinSchema } from '../../zodSchema' | ||
import { toast } from "sonner" | ||
|
||
|
||
export default function LogInForm() { | ||
const router = useRouter() | ||
|
||
const { register, handleSubmit } = useForm<z.infer<typeof signinSchema>>(); | ||
|
||
const submitForm = async (data: z.infer<typeof signinSchema>) => { | ||
const parsedData = signinSchema.parse({ | ||
email: data.email, | ||
password: data.password | ||
}) | ||
const response = await SigninAction(parsedData); | ||
if (response.success) { | ||
toast.success("login completed") | ||
router.push('/') | ||
} else { | ||
toast.error(response.error) | ||
} | ||
}; | ||
|
||
return ( | ||
<form className="grid gap-4 text-left" onSubmit={handleSubmit(submitForm)}> | ||
<div className="grid gap-2"> | ||
<Label htmlFor="email">Email</Label> | ||
<Input | ||
type="email" | ||
placeholder="johndoe@email.com" | ||
{...register('email', { required: true })} | ||
/> | ||
</div> | ||
<div className="grid gap-2"> | ||
<div className="flex items-center"> | ||
<Label htmlFor="password">Password</Label> | ||
<Link | ||
href="/forgot-password" | ||
className="ml-auto inline-block text-sm underline" | ||
> | ||
Forgot your password? | ||
</Link> | ||
</div> | ||
<Input | ||
type="password" | ||
{...register('password', { required: true })} | ||
/> | ||
</div> | ||
<Button type="submit" className="w-full bg-blue-500"> | ||
Sign in | ||
</Button> | ||
</form> | ||
) | ||
} |
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,20 @@ | ||
"use client" | ||
|
||
import Image from "next/image"; | ||
import { signIn } from "next-auth/react"; | ||
|
||
import Google from '@/public/google_icon.svg' | ||
import { Button } from "@/components/ui/button"; | ||
|
||
export default function GoogleAuthButton() { | ||
return ( | ||
<Button | ||
variant="outline" | ||
className="w-full flex gap-2" | ||
onClick={() => signIn("google", { redirect: true })} | ||
> | ||
<Image src={Google} alt="google" width={15} /> | ||
Continue with Google | ||
</Button> | ||
) | ||
} |
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,28 @@ | ||
import Link from "next/link" | ||
|
||
import SignInForm from "./components/SignInForm" | ||
import GoogleAuthButton from "./components/GoogleAuthButton" | ||
|
||
export default function Signup() { | ||
return ( | ||
<> | ||
<div className="grid gap-2 text-center"> | ||
<h1 className="text-3xl font-bold text-blue-500">Sign up</h1> | ||
<p className="text-balance text-muted-foreground"> | ||
Enter your credentials below to login to your account | ||
</p> | ||
</div> | ||
<div className="flex flex-col gap-2 mt-4 text-center text-sm"> | ||
<SignInForm /> | ||
<p className="divider">OR</p> | ||
<GoogleAuthButton /> | ||
<p> | ||
Already have an account?{" "} | ||
<Link href="/api/auth/signin" className="underline"> | ||
Sign in | ||
</Link> | ||
</p> | ||
</div> | ||
</> | ||
) | ||
} |
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.