Guest User

Untitled

a guest
Feb 16th, 2025
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. "use client";
  2.  
  3. import { lusitana } from "@/app/ui/fonts";
  4. import {
  5.   AtSymbolIcon,
  6.   KeyIcon,
  7.   ExclamationCircleIcon,
  8. } from "@heroicons/react/24/outline";
  9. import { ArrowRightIcon } from "@heroicons/react/20/solid";
  10. import { Button } from "./button";
  11. import { useSearchParams } from "next/navigation";
  12. import { useActionState } from "react";
  13. import { authenticate } from "@/app/lib/actions";
  14.  
  15. export default function LoginForm() {
  16.   const searchParams = useSearchParams();
  17.   const callbackUrl = searchParams.get("callbackUrl") || "/dashboard";
  18.   const [errorMessage, formAction, isPending] = useActionState(
  19.     authenticate,
  20.     undefined,
  21.   );
  22.   return (
  23.     <form action={formAction} className="space-y-3">
  24.       <div className="flex-1 rounded-lg bg-gray-50 px-6 pb-4 pt-8">
  25.         <h1 className={`${lusitana.className} mb-3 text-2xl`}>
  26.           Please log in to continue.
  27.         </h1>
  28.         <div className="w-full">
  29.           <div>
  30.             <label
  31.               className="mb-3 mt-5 block text-xs font-medium text-gray-900"
  32.               htmlFor="email"
  33.             >
  34.               Email
  35.             </label>
  36.             <div className="relative">
  37.               <input
  38.                 className="peer block w-full rounded-md border border-gray-200 py-[9px] pl-10 text-sm outline-2 placeholder:text-gray-500"
  39.                 id="email"
  40.                 type="email"
  41.                 name="email"
  42.                 placeholder="Enter your email address"
  43.                 required
  44.               />
  45.               <AtSymbolIcon className="pointer-events-none absolute left-3 top-1/2 h-[18px] w-[18px] -translate-y-1/2 text-gray-500 peer-focus:text-gray-900" />
  46.             </div>
  47.           </div>
  48.           <div className="mt-4">
  49.             <label
  50.               className="mb-3 mt-5 block text-xs font-medium text-gray-900"
  51.               htmlFor="password"
  52.             >
  53.               Password
  54.             </label>
  55.             <div className="relative">
  56.               <input
  57.                 className="peer block w-full rounded-md border border-gray-200 py-[9px] pl-10 text-sm outline-2 placeholder:text-gray-500"
  58.                 id="password"
  59.                 type="password"
  60.                 name="password"
  61.                 placeholder="Enter password"
  62.                 required
  63.                 minLength={6}
  64.               />
  65.               <KeyIcon className="pointer-events-none absolute left-3 top-1/2 h-[18px] w-[18px] -translate-y-1/2 text-gray-500 peer-focus:text-gray-900" />
  66.             </div>
  67.           </div>
  68.         </div>
  69.         <input type="hidden" name="redirectTo" value={callbackUrl} />
  70.         <Button className="mt-4 w-full" aria-disabled={isPending}>
  71.           Log in <ArrowRightIcon className="ml-auto h-5 w-5 text-gray-50" />
  72.         </Button>
  73.         <div className="flex h-8 items-end space-x-1">
  74.           {errorMessage && (
  75.             <>
  76.               <ExclamationCircleIcon className="h-5 w-5 text-red-500" />
  77.               <p className="text-sm text-red-500">{errorMessage}</p>
  78.             </>
  79.           )}
  80.         </div>
  81.       </div>
  82.     </form>
  83.   );
  84. }
  85.  
Advertisement
Add Comment
Please, Sign In to add comment