// Settings → Security: where you're signed in, with a way to sign the others out, and an optional alert for new sign-ins. import { useEffect, useState } from 'react'; import { useApp } from '../../context/AppContext.js'; import { listDevices, setLoginAlerts, signOutDevice, signOutOtherDevices } from '../../syncService.js'; const btn = 'rounded-lg border border-[var(--r-line)] px-3 py-1.5 text-xs hover:bg-black/5 disabled:opacity-50'; const METHODS = { password: 'password', passkey: 'passkey', mfa: 'password and code', register: 'new account' }; export function whenText(at, now = Date.now()) { const m = Math.round((now - at) / 60000); if (m < 2) return 'just now'; if (m < 120) return `${m} minutes ago`; if (m < 2880) return `${Math.round(m / 60)} hours ago`; return `${Math.round(m / 1440)} days ago`; } export default function DevicesSection() { const { authUser, setAuthUser } = useApp(); const [devices, setDevices] = useState(null); const [error, setError] = useState(''); const [busy, setBusy] = useState(false); const load = async () => { const r = await listDevices(); if (r.ok) setDevices(r.data); else setError(r.error ?? 'Could not load your devices.'); }; useEffect(() => { load(); }, []); const signOut = async (d) => { if (!window.confirm(`Sign out ${d.label}?`)) return; const r = await signOutDevice(d.id); if (!r.ok && r.status !== 404) setError(r.error ?? 'Could not sign it out.'); load(); }; const signOutOthers = async () => { if (!window.confirm('Sign out every other device? They’ll need to sign in again.')) return; setBusy(true); const r = await signOutOtherDevices(); setBusy(false); if (!r.ok) setError(r.error ?? 'Could not sign them out.'); load(); }; const toggleAlerts = async (e) => { setError(''); const r = await setLoginAlerts(e.target.checked); if (r.ok) setAuthUser({ ...authUser, loginAlerts: r.data.loginAlerts }); else setError(r.error ?? 'Could not change that.'); }; const others = (devices ?? []).filter((d) => !d.current); return (

Where you’re signed in

If you don’t recognise one, sign it out and change your password.

{devices === null && !error &&

Loading…

} {devices && ( )} {others.length > 0 && } {error &&

{error}

}
); }