File tree Expand file tree Collapse file tree 3 files changed +28
-8
lines changed
Expand file tree Collapse file tree 3 files changed +28
-8
lines changed Original file line number Diff line number Diff line change @@ -100,15 +100,12 @@ async def create_api_key(credentials: UserCredentials) -> ApiKeyResponse:
100100 HTTPException: 400 if creation fails, 401 if authentication fails
101101 """
102102 try :
103- print ("\n Create API key endpoint hit!" ) # See if we reach this endpoint
104103 print (f"Creating API key for { credentials .email } " )
105- print ( " \n Creating API key..." )
106- print (f"Test environment: { settings .ENVIRONMENT == 'TEST' } ; SKIP EMAIL VERIFICATION: { settings .SKIP_EMAIL_VERIFICATION } " )
107- log = f"Authenticating user { credentials .email } with password { credentials . password } "
104+ if settings . ENVIRONMENT == 'TEST' :
105+ print (f"Test environment: { settings .ENVIRONMENT == 'TEST' } ; SKIP EMAIL VERIFICATION: { settings .SKIP_EMAIL_VERIFICATION } " )
106+ log = f"Authenticating user { credentials .email } with password *** "
108107 user = await backend .authenticate_user (credentials .email , credentials .password )
109108 log = f"User authenticated: { user } "
110- print (f"User authenticated: { user } " )
111- print (f"User metadata: { user .user_metadata } " )
112109
113110 # Skip verification check in test environment
114111 if not (settings .ENVIRONMENT == "TEST" and settings .SKIP_EMAIL_VERIFICATION ):
Original file line number Diff line number Diff line change @@ -121,7 +121,12 @@ async def list_api_keys(user):
121121 return api_keys
122122
123123async def verify_token (request : Request , credentials : Optional [HTTPAuthorizationCredentials ] = Security (security )) -> dict :
124- """Verify JWT token and return user info with credits"""
124+ """Verify JWT token and return user info with credits"""
125+
126+ # Whatever the logic flow, first we need to make sure that there isn't a different user still authorized:
127+ db .auth .sign_out ()
128+
129+ # Now we can do the rest of the logic. run test routines first, then check guest or proper user.
125130 try :
126131 # Skip email verification in test environment
127132 if settings .ENVIRONMENT == "TEST" and settings .SKIP_EMAIL_VERIFICATION :
@@ -227,4 +232,4 @@ def generate_guest_id(request: Request) -> dict:
227232 ip = request .client .host
228233 # Hash the IP to get 32 hex chars
229234 hex_hash = hashlib .sha256 (ip .encode ()).hexdigest ()[:32 ]
230- return {"id" : f"{ UUID (hex_hash )} " }
235+ return {"id" : f"{ UUID (hex_hash )} " }
Original file line number Diff line number Diff line change 1+ BEGIN ;
2+
3+ -- Create new comprehensive service role policies
4+ CREATE POLICY " Service role has full access to API keys"
5+ ON public .api_keys
6+ FOR ALL
7+ TO service_role
8+ USING (true)
9+ WITH CHECK (true);
10+
11+ CREATE POLICY " Service role has full access to credits"
12+ ON public .credits
13+ FOR ALL
14+ TO service_role
15+ USING (true)
16+ WITH CHECK (true);
17+
18+ COMMIT ;
You can’t perform that action at this time.
0 commit comments