/* ====================================================================== 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 (
setRole("public")} style={{ cursor: "pointer" }}>

"We moved in two weeks faster than any rental we've done. Everything in one place."

Aisha R.Tenant · Maple Heights
{["Verified landlords & listings", "Protected, escrow-style payments", "Inspections and applications tracked end-to-end"].map(t => (
{t}
))}
{children}
); } function SignIn({ onRegister }) { const { db, session, setSession, toast } = useApp(); const [email, setEmail] = useState(""); const [pw, setPw] = useState(""); const [err, setErr] = useState({}); const submit = () => { const e = {}; const q = email.trim().toLowerCase(); const user = db.users.find(u => u.email.toLowerCase() === q && u.role !== "admin"); if (!q) e.email = "Enter your email"; else if (!user) e.email = "No account found for that email. Create one to get started."; if (!pw) e.pw = "Enter your password"; else if (user && user.password && user.password !== pw) e.pw = "Incorrect password"; setErr(e); if (Object.keys(e).length) return; const idKey = user.role === "tenant" ? "tenantId" : "landlordId"; const dest = destFromIntent(session.params?.intent, user, { view: "dashboard", params: {} }); setSession(s => ({ ...s, role: user.role, [idKey]: user.id, view: dest.view, params: dest.params })); toast("Welcome back, " + user.name.split(" ")[0] + "!", "ok"); }; return ( <>

Welcome back

Sign in to your Korealm account.

{ setEmail(e.target.value); setErr(x => ({ ...x, email: undefined })); }} error={err.email} /> { setPw(e.target.value); setErr(x => ({ ...x, pw: undefined })); }} error={err.pw} />

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 ( <>
{step === 0 && (

Create your account

First, tell us how you'll use Korealm.

setRoleSel("tenant")}>
I'm a tenant
Find a home, book inspections, apply and pay rent.
setRoleSel("landlord")}>
I'm a landlord
List properties, verify your identity, and collect rent.

Already have an account?

)} {step === 1 && (

Your details

Creating a {role} account.

setForm({ ...form, name: e.target.value })} error={errors.name} /> setForm({ ...form, email: e.target.value })} error={errors.email} /> setForm({ ...form, phone: e.target.value })} error={errors.phone} /> setForm({ ...form, pw: e.target.value })} error={errors.pw} />

By continuing you agree to Korealm's Terms & Privacy Policy.

)} {step === 2 && (

Check your email

We sent a 6-digit code to {form.email}.

{code.map((c, i) => ( refs.current[i] = el} className="otp" value={c} maxLength={1} inputMode="numeric" onChange={e => setDigit(i, e.target.value)} onKeyDown={e => onKey(i, e)} /> ))}
Sandbox: your code is {DEMO_CODE}
Didn't get it? ·
)} ); } function AuthScreen() { const { session, go } = useApp(); const [mode, setMode] = useState(session.params?.mode || "register"); return ( {mode === "signin" ? setMode("register")} /> : setMode("signin")} />} ); } window.AuthScreen = AuthScreen;