Branchwell

Lumen & Gesso / website · lumengesso.com / app / login / page.tsx

1'use client';
2
3import { Suspense, useState } from 'react';
4import { useSearchParams } from 'next/navigation';
5import { authClient } from '@/app/lib/auth-client';
6
7export default function LoginPage() {
8 return (
9 <Suspense fallback={<main className="auth"><div className="auth__card">Loading…</div></main>}>
10 <PasskeySignIn />
11 </Suspense>
12 );
13}
14
15function safe(next: string | null) {
16 return next && next.startsWith('/') && !next.startsWith('//') ? next : '/orders';
17}
18
19function PasskeySignIn() {
20 const params = useSearchParams();
21 const next = safe(params.get('next'));
22 const [busy, setBusy] = useState(false);
23 const [error, setError] = useState<string | null>(params.get('error') === 'link_expired'
24 ? 'That private link has expired. Use the newest link in your order email.' : null);
25
26 async function signIn() {
27 setBusy(true);
28 setError(null);
29 try {
30 const res = await authClient.signIn.passkey();
31 if (res?.error) setError('That passkey didn’t work here. Try again, or open the private link in your order email.');
32 else window.location.assign(next);
33 } catch {
34 setError('We couldn’t reach the studio. Try again in a moment.');
35 } finally {
36 setBusy(false);
37 }
38 }
39
40 return (
41 <main className="auth">
42 <div className="auth__card">
43 <h1 className="auth__title">Sign in</h1>
44 <p className="auth__body">Use your passkey: Face ID, Touch ID or your phone. There are no passwords.</p>
45 <div className="auth__form">
46 <button type="button" className="btn btn--rose btn--lg btn--block" onClick={signIn} disabled={busy}>
47 {busy ? 'Waiting for your passkey…' : 'Sign in with passkey'}
48 </button>
49 {error && <p className="auth__error">{error}</p>}
50 </div>
51 <p className="auth__body">New here? Your order email has a private link to your portrait. Open it once and save a passkey.</p>
52 </div>
53 </main>
54 );
55}