Add basic FastAPI auth and React login gate
CI / basic-check (push) Has been cancelled

This commit is contained in:
Perplexity Bot
2026-08-04 20:21:34 +00:00
parent 998c5246dd
commit 8aae681706
9 changed files with 139 additions and 456 deletions
View File
+14
View File
@@ -0,0 +1,14 @@
from datetime import timedelta
from fastapi import APIRouter, Depends, HTTPException, status
from fastapi.security import OAuth2PasswordRequestForm
from app.auth import ACCESS_TOKEN_EXPIRE_MINUTES, Token, authenticate_user, create_access_token, get_current_active_user
router = APIRouter(prefix='/auth', tags=['auth'])
@router.post('/token', response_model=Token)
async def login(form_data: OAuth2PasswordRequestForm = Depends()):
user = authenticate_user(form_data.username, form_data.password)
if not user: raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail='Incorrect username or password')
access_token = create_access_token({'sub': user.username, 'role': user.role}, timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES))
return Token(access_token=access_token)
@router.get('/me')
async def me(current_user=Depends(get_current_active_user)):
return {'username': current_user.username, 'role': current_user.role, 'disabled': current_user.disabled}