From cda971be5d15d8da2a73a968cf708544a180e532 Mon Sep 17 00:00:00 2001 From: Fidelis Huber Date: Fri, 21 Aug 2026 19:42:55 +0200 Subject: [PATCH] Persist login across app restarts (localStorage instead of sessionStorage) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .gitea/workflows/test-build-only.yml | 12 ++++++++++++ client/src/lib/authConfig.ts | 4 +++- client/src/lib/localAuth.ts | 14 ++++++++------ 3 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 .gitea/workflows/test-build-only.yml diff --git a/.gitea/workflows/test-build-only.yml b/.gitea/workflows/test-build-only.yml new file mode 100644 index 0000000..fb73e32 --- /dev/null +++ b/.gitea/workflows/test-build-only.yml @@ -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 . diff --git a/client/src/lib/authConfig.ts b/client/src/lib/authConfig.ts index 525c1db..c3a850b 100644 --- a/client/src/lib/authConfig.ts +++ b/client/src/lib/authConfig.ts @@ -12,7 +12,9 @@ const msalConfig: Configuration = { redirectUri: window.location.origin }, 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' } }; diff --git a/client/src/lib/localAuth.ts b/client/src/lib/localAuth.ts index 112cf20..c3c8995 100644 --- a/client/src/lib/localAuth.ts +++ b/client/src/lib/localAuth.ts @@ -1,12 +1,14 @@ const TOKEN_KEY = 'bv_local_token'; 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 { - return sessionStorage.getItem(TOKEN_KEY); + return localStorage.getItem(TOKEN_KEY); } export function getLocalUser(): string | null { - return sessionStorage.getItem(NAME_KEY); + return localStorage.getItem(NAME_KEY); } export async function localLogin(username: string, password: string): Promise { @@ -20,12 +22,12 @@ export async function localLogin(username: string, password: string): Promise