@@ -23,9 +23,9 @@ async def authenticate_user(email: str, password: str):
2323 session = db .auth .sign_in_with_password ({
2424 "email" : email ,
2525 "password" : password
26- })
26+ })
2727 except Exception as e :
28- raise HTTPException (status_code = 401 , detail = "This user or password does not exist." )
28+ raise HTTPException (status_code = 401 , detail = f "This user or password does not exist. { str ( e ) } " )
2929
3030 print ("Auth'ed" )
3131 user = session .user
@@ -130,14 +130,9 @@ async def verify_token(request: Request, credentials: Optional[HTTPAuthorization
130130 try :
131131 # Skip email verification in test environment
132132 if settings .ENVIRONMENT == "TEST" and settings .SKIP_EMAIL_VERIFICATION :
133- print ("Test environment detected - skipping email verification" )
133+ print ("Test environment detected - skipping email verification and checking database for user details " )
134134 is_guest = not credentials
135- if is_guest :
136- return generate_guest_id (request )
137-
138- # Fix: When in test environment, we need to use a safe way to get user_id
139- # If we have credentials, try to decode them, otherwise use a test value
140- user_id = "test_user"
135+ user_id = f"test_user{ '_guest' if is_guest else '' } "
141136 if credentials :
142137 try :
143138 decoded = jwt .decode (credentials .credentials , settings .SECRET_KEY , algorithms = ["HS256" ])
@@ -147,9 +142,9 @@ async def verify_token(request: Request, credentials: Optional[HTTPAuthorization
147142
148143 return {
149144 "user_id" : user_id ,
150- "is_guest" : False ,
145+ "is_guest" : is_guest ,
151146 "email_verified" : True , # Always verified in tests
152- "balance" : settings .USER_MAX_CREDITS
147+ "balance" : settings .GUEST_MAX_CREDITS if is_guest else settings . USER_MAX_CREDITS
153148 }
154149
155150 # Regular verification logic...
@@ -232,4 +227,23 @@ def generate_guest_id(request: Request) -> dict:
232227 ip = request .client .host
233228 # Hash the IP to get 32 hex chars
234229 hex_hash = hashlib .sha256 (ip .encode ()).hexdigest ()[:32 ]
235- return {"id" : f"{ UUID (hex_hash )} " }
230+ return {"id" : f"{ UUID (hex_hash )} " }
231+
232+ async def delete_user (user_id : str ):
233+ """Delete a user from Supabase auth system
234+
235+ Args:
236+ user_id: The ID of the user to delete
237+
238+ Raises:
239+ HTTPException: If deletion fails
240+ """
241+ try :
242+ # Use the Supabase admin auth client to delete the user
243+ db .auth .sign_out ()
244+ db .auth .admin .delete_user (user_id )
245+ print (f"User { user_id } successfully deleted" )
246+ except Exception as e :
247+ print (f"Error deleting user { user_id } : { str (e )} " )
248+ traceback .print_exc ()
249+ raise HTTPException (status_code = 400 , detail = f"Failed to delete user: { str (e )} " )
0 commit comments