feat: add password authentication to the web interface - #99
Open
harrydimas wants to merge 3 commits into
Open
Conversation
- POST/GET endpoints: login, logout, check - preHandler hook protects /api/*, skips /api/auth/* - Bearer tokens in sessionStorage, auto-attached to fetch/WebSocket - 401 response triggers login overlay - Env vars PI_WEB_AUTH_USERNAME/PASSWORD or config auth block - Logout action in action palette (Cmd+K / Ctrl+K)
|
I really don't see any benefit of this? By default it is only accessible from localhost and if you really need access from outside via password authentication, you can wrap it around a reverse proxy what is the proper solution ihmo. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds username/password authentication for the PI WEB interface, protecting it behind a login screen.

Features:
config.json(auth.enabled,auth.username,auth.password) or environment variables (PI_WEB_AUTH_USERNAME,PI_WEB_AUTH_PASSWORD)sessionStorage. Tokens expire after 24h and are never persisted to disk (server restart forces re-auth)?token=query parameterGET /api/auth/check) returns{ authEnabled, authenticated }so the client can detect whether to show the login screenServer-side:
registerPasswordAuth()plugin addsPOST /api/auth/login,POST /api/auth/logout,GET /api/auth/check, and apreHandlerhook protecting all/api/*routes (excluding/api/auth/*)Client-side:
pi-web-password-logincomponent with login form, loading state, error displaypasswordAuth.tshelpers:storedToken(),saveToken(),clearToken()http.tsattaches Bearer token to all requests; dispatchespi-web:auth-requiredevent on 401sockets.tsappends?token=to WebSocket URLs when a token is storedPiWebApp.tslistens for auth events, checks auth on load, shows login overlay--pi-*theme variables for consistent appearance across themes