From 279e371cf58259070fbc0b2320858fa94363b2e0 Mon Sep 17 00:00:00 2001 From: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com> Date: Wed, 10 Dec 2025 10:33:00 -0800 Subject: [PATCH] fix: prevent logout on network errors during token refresh (#8021) * fix: prevent logout on network errors during token refresh When network errors occur at startup (e.g., opening laptop while offline), users were being logged out because the token refresh failed and returned null to AuthService. Now on network errors or max retries exceeded, we return the stored auth data instead of clearing the session. This keeps users logged in with their existing credentials. If the token is truly invalid, the actual API request will fail later when the user tries to use Cline, rather than logging them out preemptively at startup. * chore: add changeset --- .changeset/fix-network-error-logout.md | 5 +++++ src/services/auth/providers/ClineAuthProvider.ts | 13 ++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) create mode 100644 .changeset/fix-network-error-logout.md diff --git a/.changeset/fix-network-error-logout.md b/.changeset/fix-network-error-logout.md new file mode 100644 index 00000000..5e233435 --- /dev/null +++ b/.changeset/fix-network-error-logout.md @@ -0,0 +1,5 @@ +--- +"claude-dev": patch +--- + +Fixed an issue where users were being logged out when opening the extension with network issues (e.g., opening laptop while offline). Now the extension retains your login state and will retry authentication when you make a request. diff --git a/src/services/auth/providers/ClineAuthProvider.ts b/src/services/auth/providers/ClineAuthProvider.ts index f9714bc9..7b04073d 100644 --- a/src/services/auth/providers/ClineAuthProvider.ts +++ b/src/services/auth/providers/ClineAuthProvider.ts @@ -210,11 +210,9 @@ export class ClineAuthProvider implements IAuthProvider { // Check if we've exceeded max retries if (this.refreshRetryCount >= this.MAX_REFRESH_RETRIES) { - return this.clearSession( - controller, - `Max refresh retries (${this.MAX_REFRESH_RETRIES}) exceeded. Clearing auth state.`, - storedAuthData, - ) + Logger.error(`Max refresh retries (${this.MAX_REFRESH_RETRIES}) exceeded.`) + // Don't clear session - return stored data and let API request fail later + return storedAuthData } // Try to refresh the token using the refresh token @@ -249,8 +247,9 @@ export class ClineAuthProvider implements IAuthProvider { throw refreshError } - // For network errors, return null and let retry logic handle it - return null + // For network errors, return stored data - let the API request fail later + // when the user actually tries to use Cline, not at startup + return storedAuthData } }