Spaces:
Sleeping
Sleeping
Download backend/python-service/auth.py from bardd/mike-backend: direct link, hf CLI and curl.
- Browser
- Download file 762 Bytes
-
https://huggingface.co/spaces/bardd/mike-backend/resolve/main/backend/python-service/auth.py
- Command line
-
hf download hf://spaces/bardd/mike-backend/backend/python-service/auth.py
-
curl -L -o auth.py https://huggingface.co/spaces/bardd/mike-backend/resolve/main/backend/python-service/auth.py
762 Bytes
| from __future__ import annotations | |
| from typing import Optional | |
| from fastapi import Header, HTTPException, Request | |
| from pydantic import BaseModel | |
| class UserSession(BaseModel): | |
| user_id: str | |
| email: str | |
| username: str | |
| async def current_user( | |
| request: Request, | |
| x_user_id: Optional[str] = Header(None, alias="x-user-id"), | |
| x_user_email: Optional[str] = Header(None, alias="x-user-email"), | |
| ) -> UserSession: | |
| user_id = x_user_id or request.headers.get("x-user-id") | |
| email = x_user_email or request.headers.get("x-user-email", "") | |
| if not user_id: | |
| raise HTTPException(status_code=401, detail="Missing x-user-id header.") | |
| username = email or user_id | |
| return UserSession(user_id=user_id, email=email, username=username) | |