Become a Pro / website · becomeapro.ai / src / app / login / page.tsx
| 1 | "use client"; |
| 2 | |
| 3 | import { Suspense, useEffect, useState } from "react"; |
| 4 | import { useSearchParams } from "next/navigation"; |
| 5 | import { Fingerprint } from "lucide-react"; |
| 6 | import { biolock, enrolledHere, hasReader } from "@/lib/biolock/use-biolock"; |
| 7 | |
| 8 | const buttonClass = |
| 9 | "flex h-11 w-full items-center justify-center gap-3 rounded-full font-mono text-[12.5px] font-semibold uppercase tracking-[0.07em] transition-colors disabled:pointer-events-none disabled:opacity-50"; |
| 10 | const solid = `${buttonClass} bg-foreground text-background hover:bg-foreground/85`; |
| 11 | const outline = `${buttonClass} border border-foreground/25 text-foreground hover:border-foreground/60`; |
| 12 | |
| 13 | function LoginForm() { |
| 14 | const params = useSearchParams(); |
| 15 | const next = params.get("next") || "/account"; |
| 16 | const addToken = params.get("add"); |
| 17 | const [reader, setReader] = useState<boolean | null>(null); |
| 18 | const [enrolled, setEnrolled] = useState(false); |
| 19 | const [name, setName] = useState(""); |
| 20 | const [pending, setPending] = useState(false); |
| 21 | const [error, setError] = useState<string | null>(null); |
| 22 | |
| 23 | useEffect(() => { |
| 24 | void hasReader().then(setReader); |
| 25 | setEnrolled(enrolledHere().length > 0); |
| 26 | }, []); |
| 27 | |
| 28 | const run = async (mode: "signin" | "create" | "link") => { |
| 29 | setPending(true); |
| 30 | setError(null); |
| 31 | try { |
| 32 | await biolock(mode, mode === "create" ? { name } : mode === "link" ? { token: addToken ?? "" } : {}); |
| 33 | window.location.assign(`/auth/callback?next=${encodeURIComponent(next)}`); |
| 34 | } catch (failure) { |
| 35 | setError(failure instanceof Error ? failure.message : "Sign-in failed. Try again."); |
| 36 | setEnrolled(enrolledHere().length > 0); |
| 37 | setPending(false); |
| 38 | } |
| 39 | }; |
| 40 | |
| 41 | return ( |
| 42 | <div className="w-full max-w-md"> |
| 43 | <p className="label"> |
| 44 | <i /> |
| 45 | Free account |
| 46 | </p> |
| 47 | <h1 className="display-title mt-6 text-[clamp(44px,6vw,80px)]">{addToken ? "Add this device" : "Sign in"}</h1> |
| 48 | <p className="mt-5 text-[17px] leading-relaxed text-[var(--mist)]"> |
| 49 | {addToken |
| 50 | ? "Set up this device so it signs in with its own fingerprint or face." |
| 51 | : "Save lessons to come back to. Sign in with BioLock: just your fingerprint or face, on this device. No passwords."} |
| 52 | </p> |
| 53 | {error && ( |
| 54 | <p role="alert" className="mt-8 rounded-xl border border-destructive/40 bg-destructive/10 p-4 text-sm">{error}</p> |
| 55 | )} |
| 56 | {reader === false && ( |
| 57 | <p role="status" className="mt-8 rounded-xl border border-foreground/15 p-4 text-sm text-[var(--mist)]"> |
| 58 | This device has no fingerprint or face reader, so it can't sign in. Use a phone or a computer with Touch ID, Face ID or Windows Hello. |
| 59 | </p> |
| 60 | )} |
| 61 | <div className="mt-10 max-w-[400px] space-y-3"> |
| 62 | {addToken ? ( |
| 63 | <button className={solid} disabled={!reader || pending} onClick={() => void run("link")}> |
| 64 | <Fingerprint className="size-[18px]" aria-hidden /> {pending ? "Waiting for your fingerprint…" : "Add this device"} |
| 65 | </button> |
| 66 | ) : ( |
| 67 | <> |
| 68 | {enrolled && ( |
| 69 | <button className={solid} disabled={!reader || pending} onClick={() => void run("signin")}> |
| 70 | <Fingerprint className="size-[18px]" aria-hidden /> {pending ? "Waiting for your fingerprint…" : "Sign in with BioLock"} |
| 71 | </button> |
| 72 | )} |
| 73 | <form |
| 74 | className={`space-y-3 ${enrolled ? "pt-8" : ""}`} |
| 75 | onSubmit={(event) => { event.preventDefault(); void run("create"); }} |
| 76 | > |
| 77 | {enrolled && <p className="text-sm text-[var(--mist)]">New here? Make a free account.</p>} |
| 78 | <label className="block text-sm text-[var(--mist)]" htmlFor="biolock-name">Your name</label> |
| 79 | <input |
| 80 | id="biolock-name" |
| 81 | required |
| 82 | maxLength={80} |
| 83 | autoComplete="name" |
| 84 | value={name} |
| 85 | onChange={(event) => setName(event.target.value)} |
| 86 | className="h-11 w-full rounded-full border border-foreground/25 bg-transparent px-5 text-[15px] outline-none focus:border-foreground/60" |
| 87 | /> |
| 88 | <button type="submit" className={enrolled ? outline : solid} disabled={!reader || pending || !name.trim()}> |
| 89 | <Fingerprint className="size-[18px]" aria-hidden /> Create account with BioLock |
| 90 | </button> |
| 91 | </form> |
| 92 | {!enrolled && ( |
| 93 | <p className="pt-2 text-sm text-[var(--ash)]"> |
| 94 | Already have an account on another device? Open your account page there and choose “Add a device”. |
| 95 | </p> |
| 96 | )} |
| 97 | </> |
| 98 | )} |
| 99 | </div> |
| 100 | <p className="mt-8 text-xs text-[var(--ash)]"> |
| 101 | By signing in you agree to the <a href="/account-rules" className="text-link">account rules</a>. Read the{" "} |
| 102 | <a href="/privacy" className="text-link">Privacy Policy</a>. |
| 103 | </p> |
| 104 | </div> |
| 105 | ); |
| 106 | } |
| 107 | |
| 108 | export default function LoginPage() { |
| 109 | return ( |
| 110 | <div className="page flex min-h-[80vh] items-center justify-center"> |
| 111 | <Suspense> |
| 112 | <LoginForm /> |
| 113 | </Suspense> |
| 114 | </div> |
| 115 | ); |
| 116 | } |