@@ -172,8 +172,10 @@ public async Task CivitLoginAsync(string apiToken)
172172 var secrets = await secretsManager . SafeLoadAsync ( ) ;
173173
174174 // Get id first using the api token
175- var userAccount = await civitTRPCApi . GetUserAccountDefault ( apiToken ) ;
176- var id = userAccount . Result . Data . Json . Id ;
175+ var userAccount = await civitTRPCApi . GetUserAccount ( bearerToken : apiToken ) ;
176+ var id =
177+ userAccount . InnerJson ? . Id
178+ ?? throw new InvalidOperationException ( "GetUserAccount did not contain an id" ) ;
177179
178180 // Then get the username using the id
179181 var account = await civitTRPCApi . GetUserById ( new CivitGetUserByIdRequest { Id = id } , apiToken ) ;
@@ -241,7 +243,7 @@ secrets.LykosAccountV2 is not null
241243 {
242244 IsConnected = true ,
243245 Principal = principal ,
244- User = user
246+ User = user ,
245247 }
246248 ) ;
247249
@@ -282,27 +284,55 @@ private async Task RefreshHuggingFaceAsync(Secrets secrets)
282284 if ( response . IsSuccessStatusCode && response . Content != null )
283285 {
284286 // Token is valid, user info fetched
285- logger . LogInformation ( "Hugging Face token is valid. User: {Username}" , response . Content . Name ) ;
286- OnHuggingFaceAccountStatusUpdate ( new HuggingFaceAccountStatusUpdateEventArgs ( true , response . Content . Name ) ) ;
287+ logger . LogInformation (
288+ "Hugging Face token is valid. User: {Username}" ,
289+ response . Content . Name
290+ ) ;
291+ OnHuggingFaceAccountStatusUpdate (
292+ new HuggingFaceAccountStatusUpdateEventArgs ( true , response . Content . Name )
293+ ) ;
287294 }
288295 else
289296 {
290297 // Token is likely invalid or other API error
291- logger . LogWarning ( "Hugging Face token validation failed. Status: {StatusCode}, Error: {Error}, Content: {Content}" , response . StatusCode , response . Error ? . ToString ( ) , await response . Error ? . GetContentAsAsync < string > ( ) ?? "N/A" ) ;
292- OnHuggingFaceAccountStatusUpdate ( new HuggingFaceAccountStatusUpdateEventArgs ( false , null , $ "Token validation failed: { response . StatusCode } ") ) ;
298+ logger . LogWarning (
299+ "Hugging Face token validation failed. Status: {StatusCode}, Error: {Error}, Content: {Content}" ,
300+ response . StatusCode ,
301+ response . Error ? . ToString ( ) ,
302+ await response . Error ? . GetContentAsAsync < string > ( ) ?? "N/A"
303+ ) ;
304+ OnHuggingFaceAccountStatusUpdate (
305+ new HuggingFaceAccountStatusUpdateEventArgs (
306+ false ,
307+ null ,
308+ $ "Token validation failed: { response . StatusCode } "
309+ )
310+ ) ;
293311 }
294312 }
295313 catch ( ApiException apiEx )
296314 {
297315 // Handle Refit's ApiException (network issues, non-success status codes not caught by IsSuccessStatusCode if IApiResponse isn't used directly)
298- logger . LogError ( apiEx , "Hugging Face API request failed during token validation. Content: {Content}" , await apiEx . GetContentAsAsync < string > ( ) ?? "N/A" ) ;
299- OnHuggingFaceAccountStatusUpdate ( new HuggingFaceAccountStatusUpdateEventArgs ( false , null , "API request failed during token validation." ) ) ;
316+ logger . LogError (
317+ apiEx ,
318+ "Hugging Face API request failed during token validation. Content: {Content}" ,
319+ await apiEx . GetContentAsAsync < string > ( ) ?? "N/A"
320+ ) ;
321+ OnHuggingFaceAccountStatusUpdate (
322+ new HuggingFaceAccountStatusUpdateEventArgs (
323+ false ,
324+ null ,
325+ "API request failed during token validation."
326+ )
327+ ) ;
300328 }
301329 catch ( Exception ex )
302330 {
303331 // Handle other unexpected errors
304332 logger . LogError ( ex , "An unexpected error occurred during Hugging Face token validation." ) ;
305- OnHuggingFaceAccountStatusUpdate ( new HuggingFaceAccountStatusUpdateEventArgs ( false , null , "An unexpected error occurred." ) ) ;
333+ OnHuggingFaceAccountStatusUpdate (
334+ new HuggingFaceAccountStatusUpdateEventArgs ( false , null , "An unexpected error occurred." )
335+ ) ;
306336 }
307337 }
308338 else
@@ -390,7 +420,10 @@ private void OnHuggingFaceAccountStatusUpdate(HuggingFaceAccountStatusUpdateEven
390420 else if ( e . IsConnected && HuggingFaceStatus ? . IsConnected == false )
391421 {
392422 // Assuming Username might be null for now as we are not fetching it.
393- logger . LogInformation ( "Hugging Face account connected" + ( string . IsNullOrWhiteSpace ( e . Username ) ? "" : $ " (User: { e . Username } )") ) ;
423+ logger . LogInformation (
424+ "Hugging Face account connected"
425+ + ( string . IsNullOrWhiteSpace ( e . Username ) ? "" : $ " (User: { e . Username } )")
426+ ) ;
394427 }
395428 else if ( ! e . IsConnected && ! string . IsNullOrWhiteSpace ( e . ErrorMessage ) )
396429 {
0 commit comments