Skip to content

Commit 7b7f49e

Browse files
authored
fix: handle log out error screen (#1698)
If you clicked log out, it would trigger the errorr boundary, saying "Unauthenticated", this fixes that.
1 parent e828371 commit 7b7f49e

4 files changed

Lines changed: 42 additions & 7 deletions

File tree

apps/code/src/renderer/App.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ function App() {
143143
if (!wasInMainApp.current && isInMainApp && isDarkMode) {
144144
setShowTransition(true);
145145
}
146+
if (!isAuthenticated) {
147+
setShowTransition(false);
148+
}
146149
wasInMainApp.current = isInMainApp;
147150
}, [isAuthenticated, hasCompletedOnboarding, isDarkMode]);
148151

@@ -214,9 +217,15 @@ function App() {
214217
);
215218
};
216219

220+
const content = renderContent();
221+
217222
return (
218223
<ErrorBoundary name="App">
219-
<AnimatePresence mode="wait">{renderContent()}</AnimatePresence>
224+
{isAuthenticated ? (
225+
<AnimatePresence mode="wait">{content}</AnimatePresence>
226+
) : (
227+
content
228+
)}
220229
<LoginTransition
221230
isAnimating={showTransition}
222231
isDarkMode={isDarkMode}

apps/code/src/renderer/features/auth/hooks/authMutations.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,16 @@ export function useLogoutMutation() {
7777
track(ANALYTICS_EVENTS.USER_LOGGED_OUT);
7878
resetSessionService();
7979

80-
const state = await trpcClient.auth.logout.mutate();
81-
return { state, previousState };
80+
return { previousState };
8281
},
8382
onSuccess: async ({ previousState }) => {
84-
await refreshAuthStateQuery();
8583
clearAuthScopedQueries();
8684
useAuthUiStateStore.getState().setStaleRegion(previousState.cloudRegion);
8785
useNavigationStore.getState().navigateToTaskInput();
8886
useOnboardingStore.getState().resetSelections();
87+
88+
await trpcClient.auth.logout.mutate();
89+
await refreshAuthStateQuery();
8990
},
9091
});
9192
}

apps/code/src/renderer/features/auth/stores/authStore.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,28 @@ describe("authStore", () => {
192192
exact: true,
193193
});
194194
});
195+
196+
it("clears auth state immediately on logout before the auth service responds", async () => {
197+
mockGetState.query.mockResolvedValue(authenticatedState);
198+
let resolveLogout!: () => void;
199+
mockLogout.mutate.mockImplementation(
200+
() =>
201+
new Promise<void>((resolve) => {
202+
resolveLogout = () => resolve(undefined);
203+
}),
204+
);
205+
206+
await useAuthStore.getState().checkCodeAccess();
207+
208+
const logoutPromise = useAuthStore.getState().logout();
209+
await Promise.resolve();
210+
211+
expect(useAuthStore.getState().isAuthenticated).toBe(false);
212+
expect(useAuthStore.getState().client).toBeNull();
213+
expect(useAuthStore.getState().projectId).toBeNull();
214+
expect(useAuthStore.getState().needsScopeReauth).toBe(false);
215+
216+
resolveLogout();
217+
await logoutPromise;
218+
});
195219
});

apps/code/src/renderer/features/auth/stores/authStore.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,6 @@ export const useAuthStore = create<AuthStoreState>((set) => ({
243243
sessionResetCallback?.();
244244
useSeatStore.getState().reset();
245245
useSettingsDialogStore.getState().close();
246-
clearAuthenticatedRendererState({ clearAllQueries: true });
247-
await trpcClient.auth.logout.mutate();
248-
useNavigationStore.getState().navigateToTaskInput();
249246

250247
set((state) => ({
251248
...state,
@@ -263,5 +260,9 @@ export const useAuthStore = create<AuthStoreState>((set) => ({
263260
inFlightAuthSync = null;
264261
inFlightAuthSyncKey = null;
265262
lastCompletedAuthSyncKey = null;
263+
264+
clearAuthenticatedRendererState({ clearAllQueries: true });
265+
useNavigationStore.getState().navigateToTaskInput();
266+
await trpcClient.auth.logout.mutate();
266267
},
267268
}));

0 commit comments

Comments
 (0)