Erstregistrierung als Systemadmin plus Login/Register-Dialog im Frontend.
Deploy Development / deploy (push) Successful in 34s
Test Suite / pytest-backend (push) Successful in 9s
Test Suite / lint-backend (push) Successful in 2s
Test Suite / compose-smoke (push) Has been skipped
Test Suite / k6 /api/health Baseline (push) Successful in 18s
Test Suite / playwright-smoke (push) Successful in 12s
Deploy Development / deploy (push) Successful in 34s
Test Suite / pytest-backend (push) Successful in 9s
Test Suite / lint-backend (push) Successful in 2s
Test Suite / compose-smoke (push) Has been skipped
Test Suite / k6 /api/health Baseline (push) Successful in 18s
Test Suite / playwright-smoke (push) Successful in 12s
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
45a108b4a0
commit
101376540a
7 files changed
+502
-112
No files matched your search
+202
-45
@@ -8,12 +8,26 @@ function apiHeaders(token) {
|
||||
return headers
|
||||
}
|
||||
|
||||
function parseError(body, fallback) {
|
||||
if (!body) return fallback
|
||||
if (typeof body.detail === 'string') return body.detail
|
||||
if (Array.isArray(body.detail)) {
|
||||
return body.detail.map((d) => d.msg || JSON.stringify(d)).join(', ')
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
const [health, setHealth] = useState(null)
|
||||
const [healthError, setHealthError] = useState(null)
|
||||
const [setup, setSetup] = useState(null)
|
||||
const [authMode, setAuthMode] = useState('login')
|
||||
const [token, setToken] = useState(() => localStorage.getItem(TOKEN_KEY) || '')
|
||||
const [email, setEmail] = useState('')
|
||||
const [password, setPassword] = useState('')
|
||||
const [displayName, setDisplayName] = useState('')
|
||||
const [organizationName, setOrganizationName] = useState('')
|
||||
const [passwordConfirm, setPasswordConfirm] = useState('')
|
||||
const [authError, setAuthError] = useState(null)
|
||||
const [authBusy, setAuthBusy] = useState(false)
|
||||
const [me, setMe] = useState(null)
|
||||
@@ -27,6 +41,14 @@ export default function App() {
|
||||
})
|
||||
.then(setHealth)
|
||||
.catch((err) => setHealthError(err.message))
|
||||
|
||||
fetch('/api/auth/setup-status')
|
||||
.then((res) => res.json())
|
||||
.then((data) => {
|
||||
setSetup(data)
|
||||
if (data.registration_open) setAuthMode('register')
|
||||
})
|
||||
.catch(() => setSetup({ registration_open: false, has_users: true }))
|
||||
}, [])
|
||||
|
||||
const loadSession = useCallback(async (activeToken) => {
|
||||
@@ -53,6 +75,15 @@ export default function App() {
|
||||
loadSession(token).catch((err) => setAuthError(err.message))
|
||||
}, [token, loadSession])
|
||||
|
||||
function applyLogin(data) {
|
||||
localStorage.setItem(TOKEN_KEY, data.token)
|
||||
setToken(data.token)
|
||||
setPassword('')
|
||||
setPasswordConfirm('')
|
||||
setSetup({ registration_open: false, has_users: true, user_count: 1 })
|
||||
setAuthMode('login')
|
||||
}
|
||||
|
||||
async function handleLogin(event) {
|
||||
event.preventDefault()
|
||||
setAuthBusy(true)
|
||||
@@ -63,14 +94,38 @@ export default function App() {
|
||||
headers: apiHeaders(),
|
||||
body: JSON.stringify({ email, password }),
|
||||
})
|
||||
if (!res.ok) {
|
||||
const body = await res.json().catch(() => ({}))
|
||||
throw new Error(body.detail || `Login fehlgeschlagen (${res.status})`)
|
||||
}
|
||||
const data = await res.json()
|
||||
localStorage.setItem(TOKEN_KEY, data.token)
|
||||
setToken(data.token)
|
||||
setPassword('')
|
||||
const body = await res.json().catch(() => ({}))
|
||||
if (!res.ok) throw new Error(parseError(body, `Login fehlgeschlagen (${res.status})`))
|
||||
applyLogin(body)
|
||||
} catch (err) {
|
||||
setAuthError(err.message)
|
||||
} finally {
|
||||
setAuthBusy(false)
|
||||
}
|
||||
}
|
||||
|
||||
async function handleRegister(event) {
|
||||
event.preventDefault()
|
||||
if (password !== passwordConfirm) {
|
||||
setAuthError('Passwörter stimmen nicht überein')
|
||||
return
|
||||
}
|
||||
setAuthBusy(true)
|
||||
setAuthError(null)
|
||||
try {
|
||||
const res = await fetch('/api/auth/register', {
|
||||
method: 'POST',
|
||||
headers: apiHeaders(),
|
||||
body: JSON.stringify({
|
||||
email,
|
||||
password,
|
||||
display_name: displayName,
|
||||
organization_name: organizationName || undefined,
|
||||
}),
|
||||
})
|
||||
const body = await res.json().catch(() => ({}))
|
||||
if (!res.ok) throw new Error(parseError(body, `Registrierung fehlgeschlagen (${res.status})`))
|
||||
applyLogin(body)
|
||||
} catch (err) {
|
||||
setAuthError(err.message)
|
||||
} finally {
|
||||
@@ -89,7 +144,7 @@ export default function App() {
|
||||
})
|
||||
}
|
||||
} catch {
|
||||
/* Session trotzdem lokal entfernen */
|
||||
/* lokal entfernen */
|
||||
} finally {
|
||||
localStorage.removeItem(TOKEN_KEY)
|
||||
setToken('')
|
||||
@@ -99,6 +154,8 @@ export default function App() {
|
||||
}
|
||||
}
|
||||
|
||||
const registrationOpen = setup?.registration_open === true
|
||||
|
||||
return (
|
||||
<main className="shell">
|
||||
<header className="hero">
|
||||
@@ -107,42 +164,135 @@ export default function App() {
|
||||
<p className="muted">Auth, Tenant & Actor Foundation</p>
|
||||
</header>
|
||||
|
||||
<section className="card">
|
||||
<h2>API Health</h2>
|
||||
{healthError && <p className="error">Fehler: {healthError}</p>}
|
||||
{!healthError && !health && <p>Lade …</p>}
|
||||
{health && <pre>{JSON.stringify(health, null, 2)}</pre>}
|
||||
</section>
|
||||
<section className="card auth-card">
|
||||
<h2>{token ? 'Session' : registrationOpen ? 'Ersteinrichtung' : 'Anmeldung'}</h2>
|
||||
|
||||
{!token && registrationOpen && (
|
||||
<p className="setup-hint">
|
||||
Noch kein Systemadministrator. Der erste Account wird automatisch{' '}
|
||||
<strong>Portal-Admin</strong> und erhält einen Default-Tenant.
|
||||
</p>
|
||||
)}
|
||||
|
||||
<section className="card">
|
||||
<h2>Session</h2>
|
||||
{!token && (
|
||||
<form className="form" onSubmit={handleLogin}>
|
||||
<label>
|
||||
E-Mail
|
||||
<input
|
||||
type="email"
|
||||
autoComplete="username"
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
required
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
Passwort
|
||||
<input
|
||||
type="password"
|
||||
autoComplete="current-password"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
minLength={8}
|
||||
required
|
||||
/>
|
||||
</label>
|
||||
<button type="submit" disabled={authBusy}>
|
||||
{authBusy ? 'Anmelden …' : 'Anmelden'}
|
||||
</button>
|
||||
</form>
|
||||
<>
|
||||
<div className="tabs" role="tablist">
|
||||
<button
|
||||
type="button"
|
||||
role="tab"
|
||||
className={authMode === 'login' ? 'tab active' : 'tab'}
|
||||
aria-selected={authMode === 'login'}
|
||||
onClick={() => { setAuthMode('login'); setAuthError(null) }}
|
||||
>
|
||||
Anmelden
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
role="tab"
|
||||
className={authMode === 'register' ? 'tab active' : 'tab'}
|
||||
aria-selected={authMode === 'register'}
|
||||
disabled={!registrationOpen}
|
||||
onClick={() => { setAuthMode('register'); setAuthError(null) }}
|
||||
>
|
||||
Registrieren
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{authMode === 'login' && (
|
||||
<form className="form" onSubmit={handleLogin}>
|
||||
<label>
|
||||
E-Mail
|
||||
<input
|
||||
type="email"
|
||||
autoComplete="username"
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
required
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
Passwort
|
||||
<input
|
||||
type="password"
|
||||
autoComplete="current-password"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
minLength={8}
|
||||
required
|
||||
/>
|
||||
</label>
|
||||
<button type="submit" disabled={authBusy}>
|
||||
{authBusy ? 'Anmelden …' : 'Anmelden'}
|
||||
</button>
|
||||
</form>
|
||||
)}
|
||||
|
||||
{authMode === 'register' && registrationOpen && (
|
||||
<form className="form" onSubmit={handleRegister}>
|
||||
<label>
|
||||
Anzeigename
|
||||
<input
|
||||
type="text"
|
||||
autoComplete="name"
|
||||
value={displayName}
|
||||
onChange={(e) => setDisplayName(e.target.value)}
|
||||
required
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
Organisation / Tenant (optional)
|
||||
<input
|
||||
type="text"
|
||||
value={organizationName}
|
||||
onChange={(e) => setOrganizationName(e.target.value)}
|
||||
placeholder="z. B. Mein Programm-Team"
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
E-Mail
|
||||
<input
|
||||
type="email"
|
||||
autoComplete="email"
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
required
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
Passwort
|
||||
<input
|
||||
type="password"
|
||||
autoComplete="new-password"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
minLength={8}
|
||||
required
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
Passwort bestätigen
|
||||
<input
|
||||
type="password"
|
||||
autoComplete="new-password"
|
||||
value={passwordConfirm}
|
||||
onChange={(e) => setPasswordConfirm(e.target.value)}
|
||||
minLength={8}
|
||||
required
|
||||
/>
|
||||
</label>
|
||||
<button type="submit" disabled={authBusy}>
|
||||
{authBusy ? 'Registrieren …' : 'Systemadmin anlegen'}
|
||||
</button>
|
||||
</form>
|
||||
)}
|
||||
|
||||
{authMode === 'register' && !registrationOpen && (
|
||||
<p className="muted">
|
||||
Registrierung ist geschlossen. Bitte melden Sie sich an oder wenden Sie sich an
|
||||
den Administrator.
|
||||
</p>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
{token && me && (
|
||||
@@ -151,8 +301,8 @@ export default function App() {
|
||||
Eingeloggt als <strong>{me.display_name}</strong> ({me.email})
|
||||
</p>
|
||||
<p className="muted">
|
||||
Portal-Rolle: {me.portal_role}
|
||||
{me.active_tenant_id && ` · Tenant: ${me.active_tenant_id}`}
|
||||
{me.portal_role === 'admin' ? 'Portal-Systemadmin' : `Portal-Rolle: ${me.portal_role}`}
|
||||
{context?.tenant?.name && ` · ${context.tenant.name}`}
|
||||
</p>
|
||||
<button type="button" className="secondary" onClick={handleLogout} disabled={authBusy}>
|
||||
Abmelden
|
||||
@@ -163,6 +313,13 @@ export default function App() {
|
||||
{authError && <p className="error">{authError}</p>}
|
||||
</section>
|
||||
|
||||
<section className="card">
|
||||
<h2>API Health</h2>
|
||||
{healthError && <p className="error">Fehler: {healthError}</p>}
|
||||
{!healthError && !health && <p>Lade …</p>}
|
||||
{health && <pre>{JSON.stringify(health, null, 2)}</pre>}
|
||||
</section>
|
||||
|
||||
{token && me && (
|
||||
<>
|
||||
<section className="card">
|
||||
|
||||
@@ -36,6 +36,43 @@ body {
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
|
||||
.auth-card {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.setup-hint {
|
||||
background: #eef4fc;
|
||||
border: 1px solid #c5d9f0;
|
||||
border-radius: 6px;
|
||||
padding: 0.75rem;
|
||||
font-size: 0.92rem;
|
||||
margin: 0 0 1rem;
|
||||
}
|
||||
|
||||
.tabs {
|
||||
display: flex;
|
||||
gap: 0.35rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.tab {
|
||||
background: #eee;
|
||||
color: #333;
|
||||
border: 1px solid #ccc;
|
||||
padding: 0.45rem 0.9rem;
|
||||
}
|
||||
|
||||
.tab.active {
|
||||
background: #1a4d8f;
|
||||
color: #fff;
|
||||
border-color: #1a4d8f;
|
||||
}
|
||||
|
||||
.tab:disabled {
|
||||
opacity: 0.45;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.error {
|
||||
color: #b00020;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user