@@ -88,21 +88,21 @@ async def check_auth_service_health() -> bool:
8888 try :
8989 supabase_url = os .getenv ("SUPABASE_URL" )
9090 supabase_key = os .getenv ("SUPABASE_KEY" )
91-
91+
9292 health_url = f'{ supabase_url } /auth/v1/health'
9393 headers = {'apikey' : supabase_key }
94-
94+
9595 async with aiohttp .ClientSession () as session :
9696 async with session .get (health_url , headers = headers ) as response :
9797 if not response .ok :
9898 return False
99-
99+
100100 data = await response .json ()
101101 # Check if the service is available by checking if the response contains the name field and its value is "GoTrue"
102102 is_available = data and data .get ("name" ) == "GoTrue"
103-
103+
104104 return is_available
105-
105+
106106 except aiohttp .ClientError as e :
107107 logging .error (f"Auth service connection failed: { str (e )} " )
108108 return False
@@ -117,7 +117,8 @@ async def signup_user(email: EmailStr,
117117 invite_code : Optional [str ] = None ):
118118 """User registration"""
119119 client = get_supabase_client ()
120- logging .info (f"Receive registration request: email={ email } , is_admin={ is_admin } " )
120+ logging .info (
121+ f"Receive registration request: email={ email } , is_admin={ is_admin } " )
121122 if is_admin :
122123 await verify_invite_code (invite_code )
123124
@@ -138,7 +139,8 @@ async def signup_user(email: EmailStr,
138139 # Create user tenant relationship
139140 insert_user_tenant (user_id = user_id , tenant_id = tenant_id )
140141
141- logging .info (f"User { email } registered successfully, role: { user_role } , tenant: { tenant_id } " )
142+ logging .info (
143+ f"User { email } registered successfully, role: { user_role } , tenant: { tenant_id } " )
142144
143145 if is_admin :
144146 await generate_tts_stt_4_admin (tenant_id , user_id )
@@ -147,7 +149,8 @@ async def signup_user(email: EmailStr,
147149 else :
148150 logging .error (
149151 "Supabase registration request returned no user object" )
150- raise UserRegistrationException ("Registration service is temporarily unavailable, please try again later" )
152+ raise UserRegistrationException (
153+ "Registration service is temporarily unavailable, please try again later" )
151154
152155
153156async def parse_supabase_response (is_admin , response , user_role ):
@@ -157,7 +160,7 @@ async def parse_supabase_response(is_admin, response, user_role):
157160 "email" : response .user .email ,
158161 "role" : user_role
159162 }
160-
163+
161164 session_data = None
162165 if response .session :
163166 session_data = {
@@ -166,7 +169,7 @@ async def parse_supabase_response(is_admin, response, user_role):
166169 "expires_at" : calculate_expires_at (response .session .access_token ),
167170 "expires_in_seconds" : get_jwt_expiry_seconds (response .session .access_token )
168171 }
169-
172+
170173 return {
171174 "user" : user_data ,
172175 "session" : session_data ,
@@ -206,7 +209,8 @@ async def generate_tts_stt_4_admin(tenant_id, user_id):
206209
207210
208211async def verify_invite_code (invite_code ):
209- logging .info ("detect admin registration request, start verifying invite code" )
212+ logging .info (
213+ "detect admin registration request, start verifying invite code" )
210214 logging .info (f"The INVITE_CODE obtained from consts.const: { INVITE_CODE } " )
211215 if not INVITE_CODE :
212216 logging .error ("please check the INVITE_CODE environment variable" )
@@ -219,7 +223,8 @@ async def verify_invite_code(invite_code):
219223 if invite_code != INVITE_CODE :
220224 logging .warning (
221225 f"Admin invite code verification failed: user provided='{ invite_code } ', system configured='{ INVITE_CODE } '" )
222- raise IncorrectInviteCodeException ("Please enter the correct admin invite code" )
226+ raise IncorrectInviteCodeException (
227+ "Please enter the correct admin invite code" )
223228 logging .info ("Admin invite code verification successful" )
224229
225230
@@ -246,21 +251,21 @@ async def signin_user(email: EmailStr,
246251 f"User { email } logged in successfully, session validity is { expiry_seconds } seconds, role: { user_role } " )
247252
248253 return {
249- "message" :f"Login successful, session validity is { expiry_seconds } seconds" ,
250- "data" :{
251- "user" : {
252- "id" : response .user .id ,
253- "email" : response .user .email ,
254- "role" : user_role
255- },
256- "session" : {
257- "access_token" : response .session .access_token ,
258- "refresh_token" : response .session .refresh_token ,
259- "expires_at" : expires_at ,
260- "expires_in_seconds" : expiry_seconds
261- }
254+ "message" : f"Login successful, session validity is { expiry_seconds } seconds" ,
255+ "data" : {
256+ "user" : {
257+ "id" : response .user .id ,
258+ "email" : response .user .email ,
259+ "role" : user_role
260+ },
261+ "session" : {
262+ "access_token" : response .session .access_token ,
263+ "refresh_token" : response .session .refresh_token ,
264+ "expires_at" : expires_at ,
265+ "expires_in_seconds" : expiry_seconds
262266 }
263267 }
268+ }
264269
265270
266271async def refresh_user_token (authorization , refresh_token : str ):
@@ -283,10 +288,10 @@ async def get_session_by_authorization(authorization):
283288 if user .user_metadata and 'role' in user .user_metadata :
284289 user_role = user .user_metadata ['role' ]
285290 return {"user" : {
286- "id" : user .id ,
287- "email" : user .email ,
288- "role" : user_role
289- }
290- }
291+ "id" : user .id ,
292+ "email" : user .email ,
293+ "role" : user_role
294+ }
295+ }
291296 else :
292297 raise ValueError ("Session is invalid" )
0 commit comments