Skip to content

Commit

Permalink
feat(api) added caching for token validation
Browse files Browse the repository at this point in the history
  • Loading branch information
VVoruganti committed Oct 25, 2024
1 parent 312c66a commit ebed6c0
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion api/security.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from os import getenv
from typing import Optional

from functools import lru_cache
from dotenv import load_dotenv
from fastapi import Depends, HTTPException
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
Expand All @@ -24,6 +25,11 @@ class User(BaseModel):
email: Optional[str]


@lru_cache(maxsize=50)
def validate_user(token: str):
return supabase.auth.get_user(token)


async def get_current_user(
credentials: HTTPAuthorizationCredentials = Depends(security),
) -> User:
Expand All @@ -35,7 +41,7 @@ async def get_current_user(
token = credentials.credentials

# Verify with Supabase
user = supabase.auth.get_user(token)
user = validate_user(token)

if not user:
raise HTTPException(
Expand Down

0 comments on commit ebed6c0

Please sign in to comment.