Initial commit: XDL Twitter/X video downloader
This commit is contained in:
18
backend/app/routes/auth.py
Normal file
18
backend/app/routes/auth.py
Normal file
@@ -0,0 +1,18 @@
|
||||
"""Authentication routes."""
|
||||
import os
|
||||
from fastapi import APIRouter, HTTPException, status
|
||||
from app.schemas import LoginRequest, TokenResponse
|
||||
from app.auth import create_access_token
|
||||
|
||||
router = APIRouter(prefix="/api/auth", tags=["auth"])
|
||||
|
||||
ADMIN_USERNAME = os.getenv("ADMIN_USERNAME", "admin")
|
||||
ADMIN_PASSWORD = os.getenv("ADMIN_PASSWORD", "admin")
|
||||
|
||||
|
||||
@router.post("/login", response_model=TokenResponse)
|
||||
async def login(req: LoginRequest):
|
||||
if req.username != ADMIN_USERNAME or req.password != ADMIN_PASSWORD:
|
||||
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid credentials")
|
||||
token = create_access_token({"sub": req.username})
|
||||
return TokenResponse(access_token=token)
|
||||
Reference in New Issue
Block a user