login-form
formscn/login-formFreeBlock
Simple email and password login form
Install it
npx shadcn@latest add https://formscn.space/r/login-form.jsonSource
1"use client";23import { useForm, Controller } from "react-hook-form";4import { zodResolver } from "@hookform/resolvers/zod";5import * as z from "zod";6import { Button } from "@/components/ui/button";7import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";8import { Input } from "@/components/ui/input";9import { Label } from "@/components/ui/label";10import { toast } from "sonner";11import { Checkbox } from "@/components/ui/checkbox";12import { signIn } from "@/lib/auth-client";1314const formSchema = z.object({15 email: z.string().email("Invalid email address").min(1, "Email Address is required"),16 password: z.string().min(1, "Password is required"),17 rememberMe: z.boolean(),18});1920type FormValues = z.infer<typeof formSchema>;21export function LoginFormForm() {22 const form = useForm<FormValues>({23 resolver: zodResolver(formSchema),24 defaultValues: {25 email: "",26 password: "",27 rememberMe: false,28 },29 });3031 const onSubmit = async (data: FormValues) => {32 await signIn.email({33 email: data.email,34 password: data.password,35 callbackURL: "/dashboard",36 fetchOptions: {37 onResponse: () => {38 // toast.loading("Logging in...");39 },40 onRequest: () => {41 toast.loading("Logging in...");42 },43 onSuccess: () => {44 toast.dismiss();45 toast.success("Logged in successfully!");46 },47 onError: (ctx) => {48 toast.dismiss();49 toast.error(ctx.error.message);50 },51 },52 });53 };5455 return (56 <Card className="w-full max-w-md mx-auto">57 <CardHeader>58 <CardTitle>Login Form</CardTitle>59 <CardDescription>Simple email and password login</CardDescription>60 </CardHeader>61 <CardContent>62 <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">63 <div className="space-y-2">64 <Label htmlFor="email">Email Address</Label>65 <Input66 id="email"67 type="email"68 placeholder="john@example.com"69 {...form.register("email")}70 />71 {form.formState.errors.email && (72 <p className="text-sm text-destructive">{form.formState.errors.email.message}</p>73 )}74 </div>7576 <div className="space-y-2">77 <Label htmlFor="password">Password</Label>78 <Input79 id="password"80 type="password"81// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from formscn
All 30 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| base-formbase-form | formscn | Blocks | Free | 2 deps | |
| booking-request-formbooking-request-form | formscn | Blocks | Free | 4 deps | |
| contact-formcontact-form | formscn | Blocks | Free | 4 deps | |
| detailed-application-formdetailed-application-form | formscn | Blocks | Free | 6 deps | |
| ecommerce-checkout-formecommerce-checkout-form | formscn | Blocks | Free | 4 deps | |
| event-registration-formevent-registration-form | formscn | Blocks | Free | 4 deps | |
| feedback-formfeedback-form | formscn | Blocks | Free | 4 deps | |
| job-application-formjob-application-form | formscn | Blocks | Free | 6 deps |
