import { createSignal, createMemo, Show } from "solid-js"; import { Title } from "@solidjs/meta"; import { useNavigate } from "@solidjs/router"; import { AuthLayout, PasswordInput, SocialAuthButtons } from "~/components/auth"; import { Input } from "~/components/ui"; import { Button } from "~/components/ui"; import { signup } from "~/lib/auth"; const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; interface FormErrors { name?: string; email?: string; password?: string; confirmPassword?: string; terms?: string; } type StrengthLevel = "none" | "weak" | "medium" | "strong"; export default function SignupPage() { const navigate = useNavigate(); const [name, setName] = createSignal(""); const [email, setEmail] = createSignal(""); const [password, setPassword] = createSignal(""); const [confirmPassword, setConfirmPassword] = createSignal(""); const [agreeTerms, setAgreeTerms] = createSignal(false); const [errors, setErrors] = createSignal({}); const [loading, setLoading] = createSignal(false); const [serverError, setServerError] = createSignal(""); const strength = createMemo<{ level: StrengthLevel; label: string; percent: number }>(() => { const pwd = password(); if (!pwd) return { level: "none", label: "", percent: 0 }; let score = 0; if (pwd.length >= 8) score++; if (pwd.length >= 12) score++; if (/[a-z]/.test(pwd) && /[A-Z]/.test(pwd)) score++; if (/\d/.test(pwd)) score++; if (/[^a-zA-Z0-9]/.test(pwd)) score++; if (score <= 1) return { level: "weak", label: "Weak", percent: 25 }; if (score <= 3) return { level: "medium", label: "Medium", percent: 60 }; return { level: "strong", label: "Strong", percent: 100 }; }); const strengthColors: Record = { weak: "bg-[var(--color-error)]", medium: "bg-[var(--color-warning)]", strong: "bg-[var(--color-success)]", }; function validate(): boolean { const errs: FormErrors = {}; if (!name().trim()) errs.name = "Name is required"; if (!email().trim()) errs.email = "Email is required"; else if (!EMAIL_REGEX.test(email())) errs.email = "Invalid email format"; if (!password()) errs.password = "Password is required"; else if (password().length < 8) errs.password = "Password must be at least 8 characters"; if (password() !== confirmPassword()) errs.confirmPassword = "Passwords do not match"; if (!agreeTerms()) errs.terms = "You must agree to the Terms of Service"; setErrors(errs); return Object.keys(errs).length === 0; } async function handleSubmit(e: Event) { e.preventDefault(); setServerError(""); if (!validate()) return; setLoading(true); try { await signup(name(), email(), password()); navigate("/onboarding", { replace: true }); } catch { setServerError("Something went wrong. Please try again."); } finally { setLoading(false); } } return ( Create Account — ShieldAI

Create your account

Start protecting your identity

setName(e.currentTarget.value)} error={errors().name} required /> setEmail(e.currentTarget.value)} error={errors().email} required />
setPassword(e.currentTarget.value)} error={errors().password} required />

Password strength:{" "} {strength().label}

setConfirmPassword(e.currentTarget.value)} error={errors().confirmPassword} required />

{errors().terms}

Or continue with

Already have an account?{" "} Log in

); }