From 075e6dd9eaf4bc265affa6ecaabbe1b76c21a227 Mon Sep 17 00:00:00 2001 From: schererleander Date: Wed, 2 Jul 2025 22:18:28 +0200 Subject: feat: add app pages and layout --- src/app/login/page.tsx | 149 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 src/app/login/page.tsx (limited to 'src/app/login') diff --git a/src/app/login/page.tsx b/src/app/login/page.tsx new file mode 100644 index 0000000..7d4ad9d --- /dev/null +++ b/src/app/login/page.tsx @@ -0,0 +1,149 @@ +"use client" + +import { useState } from "react" +import { signIn } from "next-auth/react" +import { useRouter } from "next/navigation" +import { zodResolver } from "@hookform/resolvers/zod" +import { useForm } from "react-hook-form" +import { Eye, EyeOff, Loader2 } from "lucide-react" +import Link from "next/link" + +import { Button } from "@/components/ui/button" +import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" +import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form" +import { Input } from "@/components/ui/input" +import { Alert, AlertDescription } from "@/components/ui/alert" + +import { loginSchema, type LoginInput } from "@/lib/validation" + +export default function SignInPage() { + const [showPassword, setShowPassword] = useState(false) + const [isLoading, setIsLoading] = useState(false) + const [error, setError] = useState("") + const router = useRouter() + + const form = useForm({ + resolver: zodResolver(loginSchema), + defaultValues: { + email: "", + password: "", + }, + }) + + const onSubmit = async (data: LoginInput) => { + setIsLoading(true) + setError("") + + try { + const result = await signIn("credentials", { + email: data.email, + password: data.password, + redirect: false, + }) + + if (result?.error) { + setError("Invalid email or password") + } else { + router.push("/") + router.refresh() + } + } catch (error) { + setError("An unexpected error occurred") + } finally { + setIsLoading(false) + } + } + + return ( +
+ + + Sign In + + Enter your email and password to access your account + + + + {error && ( + + {error} + + )} + +
+ + ( + + Email + + + + + + )} + /> + ( + + Password + +
+ + +
+
+ +
+ )} + /> + + + + +
+ Don't have an account? + + Sign up + +
+ +
+ +
+
+
+
+ ) +} \ No newline at end of file -- cgit v1.3.1