{"record":{"id":"4c5129e3467a2484","repo":"LykosAI/StabilityMatrix","slug":"lykos-account-must-be-connected-in-to-manage-oauth","errorCode":null,"errorMessage":"Lykos account must be connected in to manage OAuth connections","messagePattern":"Lykos account must be connected in to manage OAuth connections","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"StabilityMatrix.Avalonia/Services/AccountsService.cs","lineNumber":157,"sourceCode":"\n        await RefreshLykosAsync(secrets);\n    }\n\n    public async Task LykosAccountV2LogoutAsync()\n    {\n        var secrets = await secretsManager.SafeLoadAsync();\n        await secretsManager.SaveAsync(secrets with { LykosAccountV2 = null });\n\n        OnLykosAccountStatusUpdate(LykosAccountStatusUpdateEventArgs.Disconnected);\n    }\n\n    /// <inheritdoc />\n    public async Task LykosPatreonOAuthLogoutAsync()\n    {\n        var secrets = await secretsManager.SafeLoadAsync();\n        if (secrets.LykosAccountV2 is null)\n        {\n            throw new InvalidOperationException(\n                \"Lykos account must be connected in to manage OAuth connections\"\n            );\n        }\n\n        await lykosAuthApiV2.ApiV2OauthPatreon();\n\n        await RefreshLykosAsync(secrets);\n    }\n\n    public async Task CivitLoginAsync(string apiToken)\n    {\n        var secrets = await secretsManager.SafeLoadAsync();\n\n        // Get id first using the api token\n        var userAccount = await civitTRPCApi.GetUserAccount(bearerToken: apiToken);\n        var id =\n            userAccount.InnerJson?.Id\n            ?? throw new InvalidOperationException(\"GetUserAccount did not contain an id\");","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Avalonia/Services/AccountsService.cs#L139-L175","documentation":"AccountsService throws this InvalidOperationException when a Patreon OAuth logout is requested for the Lykos account but no Lykos account (secrets.LykosAccountV2) is stored. Managing OAuth connections (connect/disconnect Patreon) only makes sense when the user is already signed in to Lykos, so the service fails fast instead of silently doing nothing.","triggerScenarios":"Calling AccountsService.LykosPatreonOAuthLogoutAsync() while secrets.LykosAccountV2 is null — i.e. the user never logged in to Lykos, logged out previously (which removes the secret), or the secrets store was cleared/corrupted.","commonSituations":"User clicks 'Disconnect Patreon' after having signed out of the Lykos account; a fresh install with no Lykos login; secrets vault reset or a failed Lykos login left LykosAccountV2 unset; app state restored from a backup without account secrets.","solutions":["Ensure the user is logged in to Lykos (call LykosLoginAsync / complete the OAuth login) before attempting Patreon OAuth management","Check secrets.LykosAccountV2 for null before calling LykosPatreonOAuthLogoutAsync and route the user to login instead","Catch InvalidOperationException and surface a 'Sign in to Lykos first' message to the user"],"exampleFix":"// before\nawait accountsService.LykosPatreonOAuthLogoutAsync();\n// after\nvar secrets = await secretsManager.SafeLoadAsync();\nif (secrets.LykosAccountV2 is not null)\n{\n    await accountsService.LykosPatreonOAuthLogoutAsync();\n}\nelse\n{\n    // prompt user to connect their Lykos account first\n}","handlingStrategy":"try-catch","validationCode":"var secrets = await secretsManager.SafeLoadAsync();\nbool canManage = secrets.LykosAccountV2 is not null;","typeGuard":"bool HasLykosAccount(SecretsManager m) => m.SafeLoadAsync().GetAwaiter().GetResult().LykosAccountV2 is not null;","tryCatchPattern":"try\n{\n    await accountsService.LykosPatreonOAuthLogoutAsync();\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Lykos account\"))\n{\n    // navigate user to Lykos login flow\n}","preventionTips":["Gate Patreon OAuth UI actions on the Lykos login state","Check secrets.LykosAccountV2 before any OAuth management call","After logout, disable OAuth management controls until re-login"],"tags":["oauth","authentication","state"],"backgroundTag":"authentication-required","analyzedSha":"af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002","analyzedAt":"2026-09-12T19:02:43.389Z","contentChangedAt":"2026-09-12T19:02:43.389Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}