Fix admin authentication to use environment variables

- Update AuthService to read ADMIN_USERNAME and ADMIN_PASSWORD from environment
- Remove hardcoded admin123 password and use install.py credentials
- Add auto-redirect from root URL to admin interface
- Authentication now properly respects .env.docker configuration
This commit is contained in:
root
2025-07-05 16:17:49 -07:00
parent 3d9e8ffbf0
commit 4c474eeb23
2 changed files with 10 additions and 4 deletions

View File

@@ -351,7 +351,8 @@ app.mount("/admin", StaticFiles(directory="admin-frontend/build", html=True), na
@app.get("/")
async def root():
"""Root endpoint redirects to admin interface"""
return {"message": "Discord Fishbowl Admin Interface", "admin_url": "/admin", "socket_url": "/socket.io"}
from fastapi.responses import RedirectResponse
return RedirectResponse(url="/admin/", status_code=302)
if __name__ == "__main__":
import os

View File

@@ -19,16 +19,21 @@ class AuthService:
"""Authentication service for admin users"""
def __init__(self):
import os
self.settings = get_settings()
self.secret_key = self.settings.admin.secret_key if hasattr(self.settings, 'admin') else "fallback-secret-key"
self.algorithm = "HS256"
self.access_token_expire_minutes = 480 # 8 hours
# Get admin credentials from environment
admin_username = os.getenv("ADMIN_USERNAME", "admin")
admin_password = os.getenv("ADMIN_PASSWORD", "admin123")
# Simple in-memory user storage (replace with database in production)
self.users = {
"admin": {
"username": "admin",
"password_hash": self._hash_password("admin123"), # Default password
admin_username: {
"username": admin_username,
"password_hash": self._hash_password(admin_password),
"permissions": ["read", "write", "admin"],
"active": True
}