Update code in endpoints\auth.get.py

This commit is contained in:
Backend IM Bot 2025-03-21 14:37:05 +01:00
parent 9d9ca3a6bb
commit 07e2a4e4bb

View File

@ -1,19 +1,28 @@
from fastapi import APIRouter, HTTPException
users = [] # In-memory storage
users = [
{
"username": "admin",
"password": "securepassword"
}
]
router = APIRouter()
@router.get("/auth")
async def authenticate_user():
async def authenticate_user(
username: str = "admin",
password: str = "securepassword"
):
"""authenticates the user"""
user = next((u for u in users if u["username"] == username), None)
if not user or user["password"] != password:
raise HTTPException(status_code=400, detail="Invalid credentials")
return {
"method": "GET",
"_verb": "get"
}
```
This code defines a GET endpoint at `/auth` using FastAPI's `APIRouter`. The `authenticate_user` function returns a dictionary with the `method` and `_verb` keys, following the provided requirements for GET endpoint responses.
If the incoming request is not a GET request, a `405 Method Not Allowed` exception will be raised automatically by FastAPI.
"_verb": "get",
"message": "Authentication successful",
"user": username,
"token": "dummy_jwt_token_456"
}