Skip to content

Commit

Permalink
move get_user_id in crud_base to a static method for other classes to…
Browse files Browse the repository at this point in the history
… use
  • Loading branch information
gphorvath committed Jul 30, 2024
1 parent 87b1c03 commit dfc4ecc
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/leapfrogai_api/data/crud_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,16 @@ async def delete(self, filters: dict | None = None) -> bool:
async def _get_user_id(self) -> str:
"""Get the user_id from the API key."""

if self.db.options.headers.get("x-custom-api-key"):
result = await self.db.table("api_keys").select("user_id").execute()
user_id: str = result.data[0]["user_id"]
else:
user_id = (await self.db.auth.get_user()).user.id
return await get_user_id(self.db)

return user_id

async def get_user_id(db: AsyncClient) -> str:
"""Get the user_id from the API key."""

if db.options.headers.get("x-custom-api-key"):
result = await db.table("api_keys").select("user_id").execute()
user_id: str = result.data[0]["user_id"]
else:
user_id = (await db.auth.get_user()).user.id

return user_id

0 comments on commit dfc4ecc

Please sign in to comment.