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 { try {
body = await request.json(); body = await request.json();
} catch { } 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 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)) { if (!/^\S+@\S+\.\S+$/.test(email)) {
return NextResponse.json( return NextResponse.json(
{ error: "Enter a valid email address." }, { error: "Enter a valid email address." },
@@ -64,7 +75,13 @@ export async function POST(request: Request) {
const workspace = const workspace =
email.split("@")[0].replace(/[^a-z0-9]+/g, "-") + "-account"; email.split("@")[0].replace(/[^a-z0-9]+/g, "-") + "-account";
const passwordHash = await hashPassword(password); 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 }>( const fsRows = await query<{ id: string }>(
`INSERT INTO fs_users (id, user_id, data) `INSERT INTO fs_users (id, user_id, data)
VALUES (gen_random_uuid()::text, $1, $2::jsonb) 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 [error, setError] = useState<string | null>(null);
const emailValid = /\S+@\S+\.\S+/.test(email); 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) => { const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault(); e.preventDefault();
@@ -148,21 +153,13 @@ export default function AuthScreen({
{isSignup && ( {isSignup && (
<div className="auth-field"> <div className="auth-field">
<label className="auth-label" htmlFor="name"> <label className="auth-label" htmlFor="name">
Name{" "} Name
<span
style={{
color: "var(--fg-faint)",
letterSpacing: 0,
textTransform: "none",
}}
>
(optional)
</span>
</label> </label>
<input <input
id="name" id="name"
type="text" type="text"
autoComplete="name" autoComplete="name"
required
className="auth-input" className="auth-input"
placeholder="First name or handle" placeholder="First name or handle"
value={name} value={name}