Persist login across app restarts (localStorage instead of sessionStorage)
sessionStorage wird geleert, sobald die (installierte) PWA am Handy geschlossen wird - deshalb war nach jedem Neustart ein erneuter Login nötig. Sowohl MSAL-Cache als auch das lokale Login-Token liegen jetzt in localStorage, MSAL erneuert den Token beim Start still im Hintergrund (acquireTokenSilent), das lokale Token ist 30 Tage gültig. Temporärer test-build-only.yml Workflow zur Verifikation ohne Registry-Push. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
1537a3d08c
commit
cda971be5d
@@ -0,0 +1,12 @@
|
|||||||
|
name: Test Build Only (temporary, no push)
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: linux
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Docker build (no push)
|
||||||
|
run: docker build -t materialschein-test:local .
|
||||||
@@ -12,7 +12,9 @@ const msalConfig: Configuration = {
|
|||||||
redirectUri: window.location.origin
|
redirectUri: window.location.origin
|
||||||
},
|
},
|
||||||
cache: {
|
cache: {
|
||||||
cacheLocation: 'sessionStorage'
|
// localStorage statt sessionStorage: bleibt erhalten, wenn die (installierte) App
|
||||||
|
// geschlossen und neu gestartet wird – sonst müsste man sich jedes Mal neu anmelden.
|
||||||
|
cacheLocation: 'localStorage'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
const TOKEN_KEY = 'bv_local_token';
|
const TOKEN_KEY = 'bv_local_token';
|
||||||
const NAME_KEY = 'bv_local_name';
|
const NAME_KEY = 'bv_local_name';
|
||||||
|
|
||||||
|
// localStorage statt sessionStorage: bleibt erhalten, wenn die (installierte) App
|
||||||
|
// geschlossen und neu gestartet wird – das Token ist 30 Tage gültig (siehe routes/auth.ts).
|
||||||
export function getLocalToken(): string | null {
|
export function getLocalToken(): string | null {
|
||||||
return sessionStorage.getItem(TOKEN_KEY);
|
return localStorage.getItem(TOKEN_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getLocalUser(): string | null {
|
export function getLocalUser(): string | null {
|
||||||
return sessionStorage.getItem(NAME_KEY);
|
return localStorage.getItem(NAME_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function localLogin(username: string, password: string): Promise<string> {
|
export async function localLogin(username: string, password: string): Promise<string> {
|
||||||
@@ -20,12 +22,12 @@ export async function localLogin(username: string, password: string): Promise<st
|
|||||||
throw new Error(body.error || 'Anmeldung fehlgeschlagen.');
|
throw new Error(body.error || 'Anmeldung fehlgeschlagen.');
|
||||||
}
|
}
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
sessionStorage.setItem(TOKEN_KEY, data.token);
|
localStorage.setItem(TOKEN_KEY, data.token);
|
||||||
sessionStorage.setItem(NAME_KEY, data.name);
|
localStorage.setItem(NAME_KEY, data.name);
|
||||||
return data.name as string;
|
return data.name as string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function clearLocalAuth() {
|
export function clearLocalAuth() {
|
||||||
sessionStorage.removeItem(TOKEN_KEY);
|
localStorage.removeItem(TOKEN_KEY);
|
||||||
sessionStorage.removeItem(NAME_KEY);
|
localStorage.removeItem(NAME_KEY);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user