Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | INFRASTRUCTURE & AUTOMATION4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : MacLustr Social Engine & Remote Navigator8 * File : apps/navigator-web/src/screens/Auth.tsx9 * Module : screens10 * Repository : https://git.spboucher.ai/maclustr-social11 * Project Website : https://social.spboucher.ai12 * Created : 2026-12-0113 * Last Modified : 2026-12-0114 *15 * Author : Simon-Pierre Boucher16 * Position : Professor of Finance17 * Institution : Université du Québec en Outaouais (UQO)18 * Organization : SP Boucher19 * Website : https://spboucher.ai20 * Git : https://git.spboucher.ai21 *22 * Preferred Contact: admin@spboucher.ai23 * Technical Contact: dev@spboucher.ai24 * Security/Admin : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142// Sign-in is passkey only. There is no password field and no login form of our own anywhere in this app.43import { useEffect, useRef, useState, type ReactNode } from 'react';44import { consumeHandoff, passkeyLogin, passkeyRegister } from '../../../shared/api.ts';45import { useT } from '../i18n.ts';46import { ErrorLine } from '../ui.tsx';4748function Frame({ title, children }: { title: string; children: ReactNode }) {49 const t = useT();50 return (51 <main className="auth">52 <p className="wordmark">MacLustr <span>Navigator</span></p>53 <h1>{title}</h1>54 {children}55 <p className="fine">{t('auth.private')}</p>56 </main>57 );58}5960export function Login({ onDone }: { onDone: () => void | Promise<void> }) {61 const t = useT();62 const [busy, setBusy] = useState(false); const [err, setErr] = useState<unknown>(null);63 const go = async () => { setBusy(true); setErr(null); try { await passkeyLogin(); await onDone(); } catch (e) { setErr(e); } finally { setBusy(false); } };64 return (65 <Frame title={t('auth.title')}>66 <p>{t('auth.lead')}</p>67 <button type="button" className="btn primary" onClick={go} disabled={busy}>{busy ? t('common.working') : t('auth.signin')}</button>68 <div aria-live="polite"><ErrorLine error={err} /></div>69 </Frame>70 );71}7273/** /setup#<token> — activation link: creates the first passkey for this domain. */74export function Setup({ onDone }: { onDone: () => void | Promise<void> }) {75 const t = useT();76 const token = useRef(decodeURIComponent(window.location.hash.replace(/^#/, ''))).current;77 const [busy, setBusy] = useState(false); const [err, setErr] = useState<unknown>(null);78 const go = async () => { setBusy(true); setErr(null); try { await passkeyRegister(token); await onDone(); } catch (e) { setErr(e); } finally { setBusy(false); } };79 return (80 <Frame title={t('setup.title')}>81 {token ? <><p>{t('setup.lead')}</p><button type="button" className="btn primary" onClick={go} disabled={busy}>{busy ? t('common.working') : t('setup.create')}</button></>82 : <p className="err" role="alert">{t('setup.no_token')}</p>}83 <div aria-live="polite"><ErrorLine error={err} /></div>84 </Frame>85 );86}8788/** /handoff#<ticket> — single-use ticket issued by the other private domain. */89export function Handoff({ onDone }: { onDone: () => void | Promise<void> }) {90 const t = useT();91 const started = useRef(false);92 const [err, setErr] = useState<unknown>(null);93 useEffect(() => {94 if (started.current) return; started.current = true; // the ticket is single-use: never send it twice95 const ticket = decodeURIComponent(window.location.hash.replace(/^#/, ''));96 if (!ticket) { setErr(new Error(t('handoff.no_ticket'))); return; }97 window.history.replaceState(null, '', '/handoff'); // the ticket leaves the address bar at once98 consumeHandoff(ticket).then(() => onDone(), setErr);99 }, []); // eslint-disable-line react-hooks/exhaustive-deps100 return (101 <Frame title={t('handoff.title')}>102 {err ? <><ErrorLine error={err} /><p><a className="btn" href="/">{t('handoff.to_login')}</a></p></> : <p role="status">{t('handoff.working')}</p>}103 </Frame>104 );105}106107/** Offered while the signed-in user has no passkey bound to this domain (arrived through a handoff). */108export function AddPasskey({ onDone }: { onDone: () => void | Promise<void> }) {109 const t = useT();110 const [busy, setBusy] = useState(false); const [err, setErr] = useState<unknown>(null);111 const go = async () => { setBusy(true); setErr(null); try { await passkeyRegister(undefined, 'navigator'); await onDone(); } catch (e) { setErr(e); } finally { setBusy(false); } };112 return (113 <section className="note" aria-labelledby="addpk">114 <h2 id="addpk">{t('passkey.title')}</h2>115 <p>{t('passkey.lead')}</p>116 <button type="button" className="btn" onClick={go} disabled={busy}>{busy ? t('common.working') : t('passkey.add')}</button>117 <ErrorLine error={err} />118 </section>119 );120}121