Add local username/password login as fallback when Microsoft login isn't available
Neues "users"-Table (bcrypt-Hash, nie Klartext), POST /api/auth/login gibt ein selbst-signiertes JWT (HS256) aus. requireAuth unterscheidet MSAL- (RS256) und lokale Tokens (HS256) anhand des alg-Headers. Server legt beim Start optional ein erstes lokales Konto an, wenn SEED_ADMIN_USERNAME/SEED_ADMIN_PASSWORD als Stack-Env gesetzt sind (idempotent, Klartext-Passwort landet nie im Repo). Frontend: Login-Screen hat jetzt einen Alternativ-Link zu Benutzername/Passwort, App.tsx kombiniert MSAL- und lokalen Auth-Status. Temporärer test-build-only.yml Workflow zur Docker-Build-Verifikation ohne Registry-Push (wird nach dem Test wieder entfernt). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
7bdf4f2897
commit
97c4aa1c68
@@ -0,0 +1,31 @@
|
||||
const TOKEN_KEY = 'bv_local_token';
|
||||
const NAME_KEY = 'bv_local_name';
|
||||
|
||||
export function getLocalToken(): string | null {
|
||||
return sessionStorage.getItem(TOKEN_KEY);
|
||||
}
|
||||
|
||||
export function getLocalUser(): string | null {
|
||||
return sessionStorage.getItem(NAME_KEY);
|
||||
}
|
||||
|
||||
export async function localLogin(username: string, password: string): Promise<string> {
|
||||
const res = await fetch('/api/auth/login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ username, password })
|
||||
});
|
||||
if (!res.ok) {
|
||||
const body = await res.json().catch(() => ({}));
|
||||
throw new Error(body.error || 'Anmeldung fehlgeschlagen.');
|
||||
}
|
||||
const data = await res.json();
|
||||
sessionStorage.setItem(TOKEN_KEY, data.token);
|
||||
sessionStorage.setItem(NAME_KEY, data.name);
|
||||
return data.name as string;
|
||||
}
|
||||
|
||||
export function clearLocalAuth() {
|
||||
sessionStorage.removeItem(TOKEN_KEY);
|
||||
sessionStorage.removeItem(NAME_KEY);
|
||||
}
|
||||
Reference in New Issue
Block a user