/* ====================================================================== KOREALM — Auth: registration + email verification + sign in window.AuthScreen ====================================================================== */ const DEMO_CODE = "486 213"; // After auth, honor a pending destination (e.g. "apply to this property") when it matches the user's role. function destFromIntent(intent, user, fallback) { if (intent && intent.role === user.role && intent.view) return { view: intent.view, params: intent.params || {} }; return fallback; } function AuthShell({ children }) { const { setRole } = useApp(); return (
Sign in to your Korealm account.
New to Korealm?
> ); } function Register({ onSignIn }) { const { actions, setSession, toast, session } = useApp(); const [step, setStep] = useState(0); const [role, setRoleSel] = useState(session.params?.intent?.role || "tenant"); const [form, setForm] = useState({ name: "", email: "", phone: "", pw: "" }); const [errors, setErrors] = useState({}); const [code, setCode] = useState(["", "", "", "", "", ""]); const [user, setUser] = useState(null); const [verifying, setVerifying] = useState(false); const refs = useRef([]); const validate = () => { const e = {}; if (form.name.trim().length < 3) e.name = "Enter your full name"; if (!/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(form.email)) e.email = "Enter a valid email address"; if (form.phone.replace(/\D/g, "").length < 7) e.phone = "Enter a valid phone number"; if (form.pw.length < 8) e.pw = "Use at least 8 characters"; setErrors(e); return Object.keys(e).length === 0; }; const submitDetails = () => { if (!validate()) return; const u = actions.registerUser({ name: form.name.trim(), email: form.email.trim(), role, phone: form.phone, password: form.pw }); actions.verifyEmail(u.id); toast("Welcome to Korealm!", "ok"); const fallback = role === "tenant" ? { view: "dashboard", params: { welcome: true } } : { view: "kyc", params: { welcome: true } }; const dest = destFromIntent(session.params?.intent, u, fallback); const idKey = role === "tenant" ? "tenantId" : "landlordId"; setSession(s => ({ ...s, role, [idKey]: u.id, view: dest.view, params: dest.params })); }; const codeStr = code.join(""); const setDigit = (i, v) => { if (!/^\d?$/.test(v)) return; const next = [...code]; next[i] = v; setCode(next); if (v && i < 5) refs.current[i + 1]?.focus(); }; const onKey = (i, e) => { if (e.key === "Backspace" && !code[i] && i > 0) refs.current[i - 1]?.focus(); }; const fillDemo = () => { setCode(DEMO_CODE.replace(" ", "").split("")); refs.current[5]?.focus(); }; const verify = () => { if (codeStr.length !== 6) { toast("Enter the 6-digit code", "err"); return; } setVerifying(true); setTimeout(() => { actions.verifyEmail(user.id); setVerifying(false); toast("Email verified — welcome to Korealm!", "ok"); if (role === "tenant") setSession(s => ({ ...s, role: "tenant", tenantId: user.id, view: "dashboard", params: { welcome: true } })); else setSession(s => ({ ...s, role: "landlord", landlordId: user.id, view: "kyc", params: { welcome: true } })); }, 1100); }; return ( <>First, tell us how you'll use Korealm.
Already have an account?
Creating a {role} account.
By continuing you agree to Korealm's Terms & Privacy Policy.
We sent a 6-digit code to {form.email}.