"use client"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { useState } from "react"; import { ErrorText } from "@/components/forms"; import { Button } from "@/components/ui/button"; import { Field, FieldDescription, FieldGroup, FieldLabel } from "@/components/ui/field"; import { Input } from "@/components/ui/input"; import { authClient } from "@/lib/auth-client"; /** Signs in with Better Auth, then goes to next (already checked to be a path on this site). */ export function SignInForm({ next }: { next: string }) { const router = useRouter(); const [error, setError] = useState(""); const [pending, setPending] = useState(false); async function submit(form: FormData) { setError(""); setPending(true); const { error } = await authClient.signIn.username({ username: String(form.get("username")), password: String(form.get("password")), }); if (error) { setError(error.message ?? "That didn't work. Try again."); setPending(false); return; } router.push(next); router.refresh(); } return (
{ e.preventDefault(); void submit(new FormData(e.currentTarget)); }} > Username Password {error && {error}} No account? Create one
); }