Added support for websocket streaming cursor.
This commit is contained in:
@@ -13,6 +13,11 @@ async def get_db():
|
||||
API_KEY_NAME = "Authorization"
|
||||
api_key_header = APIKeyHeader(name=API_KEY_NAME, auto_error=False)
|
||||
|
||||
async def get_user_from_api_key(db:AsyncSession, api_key:str):
|
||||
user = await db.execute(select(User).filter(User.api_key == api_key))
|
||||
user = user.scalars().first()
|
||||
return user
|
||||
|
||||
async def get_current_user(db: AsyncSession = Depends(get_db), api_key:str = Security(api_key_header)) -> User:
|
||||
if api_key_header is None:
|
||||
raise HTTPException(
|
||||
@@ -23,8 +28,8 @@ async def get_current_user(db: AsyncSession = Depends(get_db), api_key:str = Sec
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN, detail="API key missing, provide it in the header value [Authorization]"
|
||||
)
|
||||
user = await db.execute(select(User).filter(User.api_key == api_key))
|
||||
user = user.scalars().first()
|
||||
|
||||
user= await get_user_from_api_key(db=db, api_key=api_key)
|
||||
if user is None:
|
||||
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid credentials")
|
||||
return user
|
||||
|
||||
Reference in New Issue
Block a user