clipwright/dashboard/src/main.jsx
juancarlos.cavero 1d9fef7445 feat(cloud): self-service account deletion (GDPR art. 17)
The privacy policy already told users that "deleting your account from the
dashboard removes your content" — there was no way to do it. This adds one:
Account -> Delete account in the dashboard, DELETE /api/account on the server.

The endpoint refuses API-key auth (a leaked osk_ must not destroy the account
it was issued from) and requires the caller to retype the account email; the UI
does the same, collapsed behind a danger zone that itemises what actually goes.
Erasure is immediate and irreversible, because after it there is nothing left
to authenticate a recovery request against.

The order of the steps is the design, each one a failure mode:

- Stripe cancel first, aborting everything if it fails, so we never erase a
  user we are still billing. An InvalidRequestError is treated as already
  cancelled: a portal cancellation whose webhook never landed leaves our row
  reading "active" forever, and the one account that could not be deleted
  would be the one Stripe already stopped charging.
- R2 before the database, because those rows are the only index of which
  objects belong to the user; dropping them first turns a failed purge into
  permanent orphans.
- The DB delete is one transaction over an explicit table list, not the
  declared ON DELETE CASCADEs: create_all never ALTERs an existing table, so a
  constraint added after a table shipped lives in the models and not in
  production. tests/test_account_erasure.py fails if a new table references
  users.id without joining that list.
- A reserved usage_ledger row blocks the delete: erasing under a running job
  would pull the output from beneath it and leave the reservation unsettled.

What survives, and why: the Stripe customer and its invoices (six years,
Spanish commercial law) and one account_deletions row holding a sha256 of the
email as proof the erasure happened, itself purged after five years by the
retention sweeper. app.py registers a callback so the working files in output/
and uploads/ go too instead of waiting for the hourly sweep.

Privacy policy sections 6 (EN + ES) now point at the button and name both
survivors; the Legal hub summary says the same in one line.
2026-08-24 19:12:05 +02:00

118 lines
4.7 KiB
JavaScript

import { StrictMode, useState, useEffect } from 'react'
import { createRoot } from 'react-dom/client'
import './index.css'
import App from './App.jsx'
import Landing from './Landing.jsx'
import Legal from './Legal.jsx'
import { AuthProvider, useAuth } from './contexts/AuthContext'
import { capture as captureAttribution } from './lib/attribution'
import PricingPage from './components/PricingPage'
import AccountPage from './components/AccountPage'
import LoginModal from './components/LoginModal'
function PageShell({ title, children }) {
return (
<div className="min-h-screen bg-paper text-ink2">
<header className="h-14 sm:h-16 border-b border-rule bg-paper flex items-center justify-between gap-3 px-4 sm:px-6 sticky top-0 z-20">
<a href="#app" className="font-display lowercase text-lg text-ink truncate">OpenShorts</a>
<a href="#app" className="text-sm lowercase text-muted hover:text-ink transition-colors shrink-0">← <span className="hidden sm:inline">Back to app</span><span className="sm:hidden">back</span></a>
</header>
<main className="p-4 sm:p-6 md:p-8 pb-[max(2rem,env(safe-area-inset-bottom))]">
{title && <h1 className="font-display lowercase text-2xl sm:text-3xl text-ink text-center mb-6 sm:mb-10">{title}</h1>}
{children}
</main>
</div>
);
}
function PricingView() {
const [showLogin, setShowLogin] = useState(false);
return (
<PageShell>
<PricingPage onRequireLogin={() => setShowLogin(true)} />
{showLogin && <LoginModal onClose={() => setShowLogin(false)} />}
</PageShell>
);
}
function AccountView() {
const { isSignedIn, loading } = useAuth();
useEffect(() => {
if (!loading && !isSignedIn) window.location.hash = '#/pricing';
}, [loading, isSignedIn]);
return <PageShell><AccountPage /></PageShell>;
}
// Landing spot after an account is erased. Its own view because the session is
// gone: sending the user to #/account would bounce them to pricing with no
// explanation, and "openshorts_skip_landing" would send them into the app.
function DeletedView() {
return (
<div className="min-h-screen bg-paper text-ink2 flex items-center justify-center p-6">
<div className="max-w-md text-center space-y-4">
<h1 className="font-display lowercase text-2xl sm:text-3xl text-ink">Your account is deleted</h1>
<p className="text-sm">
Your projects, clips and transcripts are gone, any subscription is
cancelled, and your API keys no longer work. We've emailed you a
confirmation with the details.
</p>
<p className="text-sm text-muted">
You're welcome back any time — signing up again with the same address
starts a brand-new, empty account.
</p>
<a href="#landing" className="btn-ghost px-4 py-2 inline-flex">Back to openshorts.app</a>
</div>
</div>
);
}
function Root() {
const resolveView = () => {
const hash = window.location.hash || '';
if (hash.startsWith('#/auth/')) return 'auth'; // AuthContext consumes then redirects
if (hash.startsWith('#/account')) return 'account';
if (hash.startsWith('#/deleted')) return 'deleted';
if (hash.startsWith('#/pricing')) return 'pricing';
if (hash === '#legal') return 'legal';
// #landing = explicit landing view (app logo); section anchors keep the landing mounted
if (['#landing', '#features', '#how-it-works', '#pricing', '#comparison', '#faq'].includes(hash)) return 'landing';
if (hash === '#app' || localStorage.getItem('openshorts_skip_landing') === '1') return 'app';
return 'landing';
};
const [view, setView] = useState(resolveView);
useEffect(() => {
const handleHashChange = () => setView(resolveView());
window.addEventListener('hashchange', handleHashChange);
return () => window.removeEventListener('hashchange', handleHashChange);
}, []);
const handleLaunchApp = () => {
localStorage.setItem('openshorts_skip_landing', '1');
window.location.hash = '#app';
setView('app');
};
if (view === 'legal') return <Legal />;
if (view === 'pricing') return <PricingView />;
if (view === 'account') return <AccountView />;
if (view === 'deleted') return <DeletedView />;
if (view === 'auth') {
return <div className="min-h-screen flex items-center justify-center bg-background text-zinc-400">Signing you in…</div>;
}
if (view === 'app') return <App />;
return <Landing onLaunchApp={handleLaunchApp} />;
}
// Before React mounts: AuthContext rewrites the URL on auth redirects, which
// would destroy the referrer and any UTM params we still need to read.
captureAttribution();
createRoot(document.getElementById('root')).render(
<StrictMode>
<AuthProvider>
<Root />
</AuthProvider>
</StrictMode>,
)