mirror of
https://github.com/temetro/temetro.git
synced 2026-07-26 11:58:14 +00:00
448159873e
Add the shadcn login-01 and signup-03 blocks (with the base-luma field/label components) and wire their forms to the Better Auth client: login → signIn.email, signup → signUp.email (12-char rule, confirm match), with error + submitting states. Dropped the non-functional "Login with Google" button. Render the block forms from the existing (auth)/login and (auth)/signup pages (deleting the blocks' duplicate app/login + app/signup routes). Replace the animated AuthShell with a static, card-based shell + brand header so onboarding/verify/reset/accept-invite match. Drop the unsupported `eslint` key from next.config. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
120 lines
3.5 KiB
TypeScript
120 lines
3.5 KiB
TypeScript
"use client";
|
|
|
|
import Link from "next/link";
|
|
import { useRouter } from "next/navigation";
|
|
import { type FormEvent, useState } from "react";
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
import {
|
|
Card,
|
|
CardContent,
|
|
CardDescription,
|
|
CardHeader,
|
|
CardTitle,
|
|
} from "@/components/ui/card";
|
|
import {
|
|
Field,
|
|
FieldDescription,
|
|
FieldGroup,
|
|
FieldLabel,
|
|
} from "@/components/ui/field";
|
|
import { Input } from "@/components/ui/input";
|
|
import { authClient } from "@/lib/auth-client";
|
|
import { cn } from "@/lib/utils";
|
|
|
|
export function LoginForm({
|
|
className,
|
|
...props
|
|
}: React.ComponentProps<"div">) {
|
|
const router = useRouter();
|
|
const [email, setEmail] = useState("");
|
|
const [password, setPassword] = useState("");
|
|
const [error, setError] = useState<string | null>(null);
|
|
const [submitting, setSubmitting] = useState(false);
|
|
|
|
const onSubmit = async (event: FormEvent) => {
|
|
event.preventDefault();
|
|
if (submitting) return;
|
|
setSubmitting(true);
|
|
setError(null);
|
|
|
|
const { error: err } = await authClient.signIn.email({
|
|
email: email.trim(),
|
|
password,
|
|
callbackURL: `${window.location.origin}/`,
|
|
});
|
|
|
|
if (err) {
|
|
setError(
|
|
err.message ??
|
|
"Could not sign in. Check your email and password and try again."
|
|
);
|
|
setSubmitting(false);
|
|
return;
|
|
}
|
|
router.push("/");
|
|
};
|
|
|
|
return (
|
|
<div className={cn("flex flex-col gap-6", className)} {...props}>
|
|
<Card>
|
|
<CardHeader>
|
|
<CardTitle>Welcome back</CardTitle>
|
|
<CardDescription>Sign in to your clinician account</CardDescription>
|
|
</CardHeader>
|
|
<CardContent>
|
|
<form onSubmit={onSubmit}>
|
|
<FieldGroup>
|
|
{error && (
|
|
<p className="rounded-2xl bg-destructive/10 px-3 py-2 text-sm text-destructive">
|
|
{error}
|
|
</p>
|
|
)}
|
|
<Field>
|
|
<FieldLabel htmlFor="email">Email</FieldLabel>
|
|
<Input
|
|
autoComplete="email"
|
|
id="email"
|
|
onChange={(e) => setEmail(e.target.value)}
|
|
placeholder="you@clinic.org"
|
|
required
|
|
type="email"
|
|
value={email}
|
|
/>
|
|
</Field>
|
|
<Field>
|
|
<div className="flex items-center">
|
|
<FieldLabel htmlFor="password">Password</FieldLabel>
|
|
<Link
|
|
className="ml-auto inline-block text-sm underline-offset-4 hover:underline"
|
|
href="/forgot-password"
|
|
>
|
|
Forgot your password?
|
|
</Link>
|
|
</div>
|
|
<Input
|
|
autoComplete="current-password"
|
|
id="password"
|
|
onChange={(e) => setPassword(e.target.value)}
|
|
required
|
|
type="password"
|
|
value={password}
|
|
/>
|
|
</Field>
|
|
<Field>
|
|
<Button disabled={submitting} type="submit">
|
|
{submitting ? "Signing in…" : "Sign in"}
|
|
</Button>
|
|
<FieldDescription className="text-center">
|
|
Don't have an account?{" "}
|
|
<Link href="/signup">Sign up</Link>
|
|
</FieldDescription>
|
|
</Field>
|
|
</FieldGroup>
|
|
</form>
|
|
</CardContent>
|
|
</Card>
|
|
</div>
|
|
);
|
|
}
|