diff --git a/src/app/(auth)/sign-in/email/login-form.tsx b/src/app/(auth)/sign-in/email/login-form.tsx new file mode 100644 index 0000000..d41e824 --- /dev/null +++ b/src/app/(auth)/sign-in/email/login-form.tsx @@ -0,0 +1,143 @@ +"use client"; + +import { z } from "zod"; + +import { Button } from "@/components/ui/button"; +import { Input } from "@/components/ui/input"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { useForm } from "react-hook-form"; +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form"; +import { pageTitleStyles } from "@/styles/common"; +import { cn } from "@/lib/utils"; +import { useServerAction } from "zsa-react"; +import Link from "next/link"; +import { useToast } from "@/components/ui/use-toast"; +import { signInAction } from "./actions"; +import { LoaderButton } from "@/components/loader-button"; +import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; +import { Terminal } from "lucide-react"; + +const registrationSchema = z.object({ + email: z.string().email(), + password: z.string().min(8), +}); + +export default function LoginForm() { + const { toast } = useToast(); + + const { execute, isPending, error, reset } = useServerAction(signInAction, { + onError({ err }) { + toast({ + title: "Something went wrong", + description: err.message, + variant: "destructive", + }); + }, + onSuccess() { + toast({ + title: "Let's Go!", + description: "Enjoy your session", + }); + }, + }); + + const form = useForm>({ + resolver: zodResolver(registrationSchema), + defaultValues: { + email: "", + password: "", + }, + }); + + function onSubmit(values: z.infer) { + execute(values); + } + + return ( +
+

Sign In

+ +
+ + ( + + Email + + + + + + )} + /> + + ( + + Password + + + + + + )} + /> + + {error && ( + + + Uhoh, we couldn't log you in + {error.message} + + )} + + + Sign In + + + + +
+ +
+ +
+
+ +
+
+ + Or + +
+
+ + +
+ ); +} diff --git a/src/app/(auth)/sign-in/email/page.tsx b/src/app/(auth)/sign-in/email/page.tsx index a25d947..9308b9e 100644 --- a/src/app/(auth)/sign-in/email/page.tsx +++ b/src/app/(auth)/sign-in/email/page.tsx @@ -1,143 +1,10 @@ -"use client"; +import { getCurrentUser } from "@/lib/session"; +import { redirect } from "next/navigation"; +import LoginForm from "./login-form"; -import { z } from "zod"; +export default async function SignInPage() { + const user = await getCurrentUser(); + if (user) redirect("/dashboard"); -import { Button } from "@/components/ui/button"; -import { Input } from "@/components/ui/input"; -import { zodResolver } from "@hookform/resolvers/zod"; -import { useForm } from "react-hook-form"; -import { - Form, - FormControl, - FormField, - FormItem, - FormLabel, - FormMessage, -} from "@/components/ui/form"; -import { pageTitleStyles } from "@/styles/common"; -import { cn } from "@/lib/utils"; -import { useServerAction } from "zsa-react"; -import Link from "next/link"; -import { useToast } from "@/components/ui/use-toast"; -import { signInAction } from "./actions"; -import { LoaderButton } from "@/components/loader-button"; -import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; -import { Terminal } from "lucide-react"; - -const registrationSchema = z.object({ - email: z.string().email(), - password: z.string().min(8), -}); - -export default function SignInPage() { - const { toast } = useToast(); - - const { execute, isPending, error, reset } = useServerAction(signInAction, { - onError({ err }) { - toast({ - title: "Something went wrong", - description: err.message, - variant: "destructive", - }); - }, - onSuccess() { - toast({ - title: "Let's Go!", - description: "Enjoy your session", - }); - }, - }); - - const form = useForm>({ - resolver: zodResolver(registrationSchema), - defaultValues: { - email: "", - password: "", - }, - }); - - function onSubmit(values: z.infer) { - execute(values); - } - - return ( -
-

Sign In

- -
- - ( - - Email - - - - - - )} - /> - - ( - - Password - - - - - - )} - /> - - {error && ( - - - Uhoh, we couldn't log you in - {error.message} - - )} - - - Sign In - - - - -
- -
- -
-
- -
-
- - Or - -
-
- - -
- ); + return ; }