From 6d0230def515682a09c7624b74f17b787847f605 Mon Sep 17 00:00:00 2001 From: Coldot <41678750+Coldot@users.noreply.github.com> Date: Fri, 21 Mar 2025 02:09:45 +0900 Subject: [PATCH] Feat: Implement `get_current_user()` --- src/auth/dependencies.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/auth/dependencies.py diff --git a/src/auth/dependencies.py b/src/auth/dependencies.py new file mode 100644 index 0000000..4e1d847 --- /dev/null +++ b/src/auth/dependencies.py @@ -0,0 +1,17 @@ +from fastapi import Header, HTTPException +from typing import Annotated +import uuid + +async def get_current_user(x_auth_sub: Annotated[str | None, Header()] = None) -> uuid.UUID: + if not x_auth_sub: + raise HTTPException( + status_code=401, + detail="Unauthorized" + ) + try: + return uuid.UUID(x_auth_sub) + except ValueError: + raise HTTPException( + status_code=401, + detail="Unauthorized" + ) \ No newline at end of file