sign in with username only restored

This commit is contained in:
makearmy 2025-09-27 14:44:41 -04:00
parent bce0c5063b
commit c7511b98fc
2 changed files with 68 additions and 65 deletions

View file

@ -8,7 +8,7 @@ type Props = { nextPath?: string };
export default function SignIn({ nextPath = "/portal" }: Props) {
const router = useRouter();
const [email, setEmail] = useState("");
const [identifier, setIdentifier] = useState(""); // email OR username
const [password, setPassword] = useState("");
const [showPassword, setShowPassword] = useState(false);
const [loading, setLoading] = useState(false);
@ -24,7 +24,7 @@ export default function SignIn({ nextPath = "/portal" }: Props) {
method: "POST",
credentials: "include",
headers: { "Content-Type": "application/json", Accept: "application/json" },
body: JSON.stringify({ email, password }),
body: JSON.stringify({ identifier, password }),
});
const txt = await res.text();
@ -36,30 +36,31 @@ export default function SignIn({ nextPath = "/portal" }: Props) {
throw new Error(message);
}
router.replace(nextPath); // ALWAYS /portal
// Always land on the portal in this new flow
router.replace(nextPath);
router.refresh();
} catch (e: any) {
setErr(e?.message || "Unable to sign in.");
} finally {
setLoading(false);
}
}, [email, password, nextPath, router]);
}, [identifier, password, nextPath, router]);
return (
<div className="mx-auto max-w-md rounded-lg border p-6">
<h1 className="mb-1 text-2xl font-semibold">Sign In</h1>
<p className="mb-6 text-sm opacity-70">Welcome back! Enter your credentials to continue.</p>
<p className="mb-6 text-sm opacity-70">Use your email <em>or</em> username with your password.</p>
<form className="space-y-4" onSubmit={onSubmit}>
<div className="space-y-1">
<label className="text-sm font-medium">Email</label>
<label className="text-sm font-medium">Email or Username</label>
<input
type="email"
autoComplete="email"
type="text"
autoComplete="username"
className="w-full rounded-md border px-3 py-2"
placeholder="you@example.com"
value={email}
onChange={(e) => setEmail(e.currentTarget.value)}
placeholder="you@example.com or your-handle"
value={identifier}
onChange={(e) => setIdentifier(e.currentTarget.value)}
required
/>
</div>
@ -103,9 +104,7 @@ export default function SignIn({ nextPath = "/portal" }: Props) {
<div className="mt-4 text-center text-sm">
<span className="opacity-70">New here?</span>{" "}
<a className="underline" href={"/auth/sign-up"}>
Create an account
</a>
<a className="underline" href={"/auth/sign-up"}>Create an account</a>
</div>
</div>
);