Spaces:
Paused
Paused
Download app/api/api_v1/endpoints/auth.py from Fred808/Desk-Back2: direct link, hf CLI and curl.
- Browser
- Download file 618 Bytes
-
https://huggingface.co/spaces/Fred808/Desk-Back2/resolve/main/app/api/api_v1/endpoints/auth.py
- Command line
-
hf download hf://spaces/Fred808/Desk-Back2/app/api/api_v1/endpoints/auth.py
-
curl -L -o auth.py https://huggingface.co/spaces/Fred808/Desk-Back2/resolve/main/app/api/api_v1/endpoints/auth.py
618 Bytes
| from fastapi import APIRouter, Depends, HTTPException | |
| from app.services.auth_service import authenticate_user, create_access_token | |
| from app.models.auth import LoginRequest, LoginResponse | |
| router = APIRouter() | |
| async def login(user_data: LoginRequest): | |
| user = await authenticate_user(user_data.email, user_data.password) | |
| if not user: | |
| raise HTTPException(status_code=401, detail="Invalid credentials") | |
| access_token = create_access_token(data={"sub": user.email}) | |
| return LoginResponse(access_token=access_token, token_type="bearer", user=user) | |