[Bug]Language selector on login page silently fails — preference not persisted (401 Unauthorized)
Hey there! 👋 Thanks for taking the time to report this bug — we appreciate it!
Please keep in mind: PegaProx is developed and maintained entirely by volunteers in our free time. We do our best, but we can't work magic 🪄 — please be patient, we'll get to your issue as soon as we can.
Want to help keep PegaProx alive?
- ⭐ Star the project — it's free and helps a lot!
- 💖 Become a Sponsor — helps us dedicate more time to development
- 🤝 Contributing code or docs is always welcome too!
Describe the bug
The login page always renders in German regardless of the user's saved language preference or what language flag they click. Two separate issues combine to cause this:
- The language flag buttons on the login page fire
PUT /api/user/preferenceswithout an auth token, returning401 Unauthorized— so clicking a flag never actually saves anything - The login page has no mechanism to read the user's previously saved language preference before authentication completes
The authenticated UI works correctly — language preference saves and restores properly when set while logged in. The bug is isolated entirely to the pre-authentication login page.
Steps to Reproduce
- Set your language preference to English from within the authenticated UI
- Log out
- Observe login page renders in German regardless of saved preference
- Open browser DevTools → Console tab
- Click any language flag on the login page (e.g. EN)
- Observe
PUT /api/user/preferences 401 (UNAUTHORIZED)error in console - Refresh the page — language reverts to German again
Expected behavior
The login page should either:
- Read the user's previously saved language preference from a local cache (localStorage/cookie) and apply it before rendering, or
- Fall back to browser language detection via
navigator.languageso users are presented with their browser's preferred language rather than a hardcoded server default
Once logged in, the saved preference should take priority over everything else.
Environment
- PegaProx Version: 0.9.9 Beta
- Installation Method: Docker
- OS: PiKVM OS (Arch Linux ARM) on Raspberry Pi 4
- Browser: Chrome
- Behind Reverse Proxy? No — direct access on port 5000
- UI? Modern Layout
Logs
From the Developer console in Chrome when attempting to logout and then setting the Language prior to logging back in.
GET https://pegaprox.local:5000/api/auth/check?t=<timestamp> 401 (UNAUTHORIZED)
PUT https://pegaprox.local:5000/api/user/preferences 401 (UNAUTHORIZED)
PUT https://pegaprox.local:5000/api/user/preferences 401 (UNAUTHORIZED)
PUT https://pegaprox.local:5000/api/user/preferences 401 (UNAUTHORIZED)
Screenshots
(Console errors visible when clicking language flag on login page — PUT to /api/user/preferences returns 401 before authentication)
Suggested Fix
Three options in order of simplicity:
Option 1 (Recommended — frontend only, no backend changes): On login page load, detect browser language via navigator.language and apply it before rendering. Requires zero API calls and zero authentication.
const browserLang = navigator.language.split('-')[0]; // 'en' from 'en-US'
// map to supported language or fall back to 'en'
Option 2: Store the login page language selection in localStorage or a cookie (e.g. pegaprox_lang=en) rather than via an authenticated API call. Read and apply it on every page load before rendering.
Option 3: Queue the language preference selected on the login page and replay the PUT /api/user/preferences call immediately after successful authentication completes.
Suggested priority order on login page load:
- localStorage/cookie cached value (set by previous login page interaction)
- Browser
navigator.language - Server default (currently hardcoded German)
Then post-login:
- Saved user preference from database overrides everything
Workaround
Log in using the default German language, then change language from within the authenticated UI. The preference persists correctly when set while authenticated and will be restored correctly on subsequent logins — the bug is isolated to the pre-authentication login page rendering only.
Checklist
- [x] I have searched existing issues to make sure this is not a duplicate
- [x] I am using the latest version of PegaProx
Hey @DarmokNoob, both diagnoses are spot on. The flag buttons were always wired to changeLanguage() which unconditionally fires PUT /api/user/preferences — that 401's on the login page where the session cookie doesn't exist yet. And we were initialising the language state from a server-side default with no client-side persistence read.
Fix on a branch: LanguageSwitcher now reads AuthContext; when unauthenticated it routes through a new applyLanguage() that only persists to localStorage. Initial state reads from localStorage first (pegaprox-language key, validated against the supported-langs allowlist as a tampering safeguard), falls back to navigator.language mapped to a supported code, then to de as final default. Will land in the next build.
Side note — nice repro steps, made the verification trivial.
— MK
Fixed in v0.9.10. web/src/contexts.js reads pegaprox-language from localStorage with allowlist validation, falls back to navigator.language mapped onto our supported langs, then de. The flag buttons on the unauthenticated login page no longer fire PUT /api/user/preferences (would have 401'd); they route through applyLanguage() which only persists locally.
Both diagnoses you described are addressed. Closing.
— MK
You've got a great product @mkellermann97 and I'm happy to help anyway I can! Already downloaded the new release. 😁 Keep it up!