feat(auth): make Name field required on signup

This commit is contained in:
2026-06-08 10:45:26 -07:00
parent 0c56ed4cc5
commit d7187abedc
2 changed files with 29 additions and 15 deletions

View File

@@ -19,13 +19,24 @@ export async function POST(request: Request) {
try {
body = await request.json();
} catch {
return NextResponse.json({ error: "Invalid request body." }, { status: 400 });
return NextResponse.json(
{ error: "Invalid request body." },
{ status: 400 },
);
}
const email = String(body.email ?? "").trim().toLowerCase();
const email = String(body.email ?? "")
.trim()
.toLowerCase();
const password = String(body.password ?? "");
const name = body.name ? String(body.name).trim() : null;
const name = body.name ? String(body.name).trim() : "";
if (!name) {
return NextResponse.json(
{ error: "Enter your name to set up your workspace." },
{ status: 400 },
);
}
if (!/^\S+@\S+\.\S+$/.test(email)) {
return NextResponse.json(
{ error: "Enter a valid email address." },
@@ -64,7 +75,13 @@ export async function POST(request: Request) {
const workspace =
email.split("@")[0].replace(/[^a-z0-9]+/g, "-") + "-account";
const passwordHash = await hashPassword(password);
const data = JSON.stringify({ email, name, image: null, workspace, passwordHash });
const data = JSON.stringify({
email,
name,
image: null,
workspace,
passwordHash,
});
const fsRows = await query<{ id: string }>(
`INSERT INTO fs_users (id, user_id, data)
VALUES (gen_random_uuid()::text, $1, $2::jsonb)

View File

@@ -27,7 +27,12 @@ export default function AuthScreen({
const [error, setError] = useState<string | null>(null);
const emailValid = /\S+@\S+\.\S+/.test(email);
const canSubmit = emailValid && password.length >= 8 && !submitting;
const canSubmit = isSignup
? emailValid &&
password.length >= 8 &&
name.trim().length > 0 &&
!submitting
: emailValid && password.length >= 8 && !submitting;
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
@@ -148,21 +153,13 @@ export default function AuthScreen({
{isSignup && (
<div className="auth-field">
<label className="auth-label" htmlFor="name">
Name{" "}
<span
style={{
color: "var(--fg-faint)",
letterSpacing: 0,
textTransform: "none",
}}
>
(optional)
</span>
Name
</label>
<input
id="name"
type="text"
autoComplete="name"
required
className="auth-input"
placeholder="First name or handle"
value={name}