fix: auth PGRST116 — replace .single() with .execute() + check data
Browse files
auth.py
CHANGED
|
@@ -8,13 +8,15 @@ async def verify_api_key(api_key: str) -> dict:
|
|
| 8 |
if not api_key or not api_key.startswith("nacra-"):
|
| 9 |
raise HTTPException(401, "Invalid API key. Keys start with nacra-")
|
| 10 |
res = (supabase.table("users")
|
| 11 |
-
.select("*")
|
| 12 |
-
.eq("
|
|
|
|
|
|
|
| 13 |
if not res.data:
|
| 14 |
raise HTTPException(401, "Invalid or inactive API key")
|
| 15 |
-
return res.data
|
| 16 |
|
| 17 |
async def get_user(user_id: str) -> dict:
|
| 18 |
-
res = supabase.table("users").select("*").eq("id", user_id).
|
| 19 |
if not res.data: raise HTTPException(404, "User not found")
|
| 20 |
-
return res.data
|
|
|
|
| 8 |
if not api_key or not api_key.startswith("nacra-"):
|
| 9 |
raise HTTPException(401, "Invalid API key. Keys start with nacra-")
|
| 10 |
res = (supabase.table("users")
|
| 11 |
+
.select("*")
|
| 12 |
+
.eq("api_key_hash", _hash(api_key))
|
| 13 |
+
.eq("is_active", True)
|
| 14 |
+
.execute())
|
| 15 |
if not res.data:
|
| 16 |
raise HTTPException(401, "Invalid or inactive API key")
|
| 17 |
+
return res.data[0]
|
| 18 |
|
| 19 |
async def get_user(user_id: str) -> dict:
|
| 20 |
+
res = supabase.table("users").select("*").eq("id", user_id).execute()
|
| 21 |
if not res.data: raise HTTPException(404, "User not found")
|
| 22 |
+
return res.data[0]
|