BloopAI/vibe-kanban · warning · ApiError

Logout failed with status ${response.status}

Error message

Logout failed with status ${response.status}

What it means

oauthApi.logout POSTs /api/auth/logout and throws ApiError('Logout failed with status <code>', status, response) when the response is not OK. Unlike other endpoints it does not call handleApiResponse, so any non-OK status (401, 500, 502) becomes this error; the session cookie may or may not have actually been cleared.

Source

Thrown at packages/web-core/src/shared/lib/api.ts:1290

  },

  localLogin: async (
    email: string,
    password: string
  ): Promise<ProfileResponse> => {
    const response = await makeRequest('/api/auth/local/login', {
      method: 'POST',
      body: JSON.stringify({ email, password }),
    });
    return handleApiResponse<ProfileResponse>(response);
  },

  logout: async (): Promise<void> => {
    const response = await makeRequest('/api/auth/logout', {
      method: 'POST',
    });
    if (!response.ok) {
      throw new ApiError(
        `Logout failed with status ${response.status}`,
        response.status,
        response
      );
    }
  },

  /** Returns the current access token for the remote server (auto-refreshes if needed) */
  getToken: async (): Promise<TokenResponse> => {
    const response = await makeRequest('/api/auth/token');
    if (response.status === 401) {
      throw new ApiError('Unauthorized', 401, response);
    }
    return handleApiResponse<TokenResponse>(response);
  },

  /** Returns the user ID of the currently authenticated user */
  getCurrentUser: async (): Promise<CurrentUserResponse> => {

View on GitHub (pinned to 4deb7eca8f)

Solutions

  1. Ignore or downgrade the error client-side if status is 401 — the session is already invalid, so clear local state and treat the user as logged out
  2. Clear local auth state (cookies, cached tokens/profile) and redirect to the login screen regardless of server response
  3. Verify the backend is running and reachable if the status is 5xx/502, then retry the logout
  4. Check backend logs for the session-clearing failure if 500 persists

Example fix

// before
if (!response.ok) {
  throw new ApiError(`Logout failed with status ${response.status}`, response.status, response);
}
// after
if (!response.ok && response.status !== 401) {
  throw new ApiError(`Logout failed with status ${response.status}`, response.status, response);
}
// 401 means the session was already gone — proceed with local cleanup either way.
Defensive patterns

Strategy: try-catch

Validate before calling

// Only attempt logout if a session likely exists
const status = await oauthApi.status();
if (!status.authenticated) return clearLocalAuthState();

Type guard

function isLogoutError(e: unknown): e is ApiError & { status: number } {
  return e instanceof ApiError && e.message.startsWith('Logout failed with status');
}

Try / catch

try {
  await oauthApi.logout();
} catch (e) {
  if (isLogoutError(e) && e.status === 401) {
    // session already gone — treat as logged out
  } else {
    showToast('Logout failed on the server; local session cleared anyway');
  }
} finally {
  clearLocalAuthState();
  navigateToLogin();
}

Prevention

When it happens

Trigger: Logging out when POST /api/auth/logout returns non-OK: auth session already invalid/expired server-side (401), backend error while clearing the session (500), or the local backend is down so a proxy error status is returned.

Common situations: Session already expired server-side so the logout endpoint rejects the call; backend restarted with new signing keys invalidating old cookies; remote host unreachable during logout; reverse proxy returning 502 when the backend is stopped.

Related errors


AI-assisted analysis of BloopAI/vibe-kanban@4deb7eca8f (2026-08-29). Data as JSON: /api/errors/1d169567339d0eef. Report an issue: GitHub.