Skip to content

Commit 8edaf21

Browse files
committed
RLS policy requires service key instead of anon key
1 parent 53c696a commit 8edaf21

3 files changed

Lines changed: 7 additions & 3 deletions

File tree

app/core/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ class Settings(BaseSettings):
2626

2727
# Supabase postgres db settings
2828
DATABASE_URL: str
29-
DATABASE_KEY: str
29+
DATABASE_KEY: str = ""
30+
DATABASE_ANON_KEY: str = ""
31+
DATABASE_SERVICE_ROLE_KEY: str = ""
3032

3133
OPERATION_COSTS: Dict[str, OperationCost] = {
3234
"basic_analysis": {

app/core/db.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from supabase import create_client, Client
22
from .config import settings
33

4+
print("Creating Supabase client with url ", settings.DATABASE_URL)
5+
46
db: Client = create_client(
57
settings.DATABASE_URL,
6-
settings.DATABASE_KEY
8+
settings.DATABASE_SERVICE_ROLE_KEY
79
)

app/core/security.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ async def verify_token(request: Request, credentials: Optional[HTTPAuthorization
180180
print("getting credits for user:", user_id)
181181
credits = db.table('credits').select('*').eq('user_id', user_id).maybe_single().execute()
182182
print("Credits:", credits)
183-
if not credits.data:
183+
if not credits or not credits.data:
184184
print(f"No credits yet for {user_id if credentials else 'anonymous user'}. Creating...")
185185
if is_guest: # if the guest is not in the credits table, create it with the max credit amount
186186
init_guest_data = {

0 commit comments

Comments
 (0)