Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(desktop): sign out in the app instead of opening a browser (#7833)

Eric Hayesfa56c3a1ac79
diff --git a/apps/web/src/lib/core/auth/logout.test.ts b/apps/web/src/lib/core/auth/logout.test.ts
index 2910ec4d08..8b45185d22 100644
--- a/apps/web/src/lib/core/auth/logout.test.ts
+++ b/apps/web/src/lib/core/auth/logout.test.ts
@@ -4,8 +4,9 @@ import { isCancelledError, QueryClient } from '@tanstack/solid-query';
import { createRoot } from 'solid-js';
import { describe, expect, it, vi } from 'vitest';
-const { client, navigate } = vi.hoisted(() => ({
+const { client, isTauri, navigate } = vi.hoisted(() => ({
client: { current: undefined as QueryClient | undefined },
+ isTauri: vi.fn(() => false),
navigate: vi.fn(),
}));
vi.mock('@queries/client', () => ({
@@ -28,10 +29,16 @@ vi.mock('@queries/email/local-drafts', () => ({
flushLocalDrafts: vi.fn(async () => {}),
listLocalDrafts: vi.fn(async () => []),
}));
-vi.mock('@core/constant/servers', () => ({ SERVER_HOSTS: {} }));
+vi.mock('@core/constant/servers', () => ({
+ SERVER_HOSTS: { 'auth-logout': 'https://auth.example.com/oauth2/logout' },
+}));
vi.mock('@core/mobile/isNativeMobilePlatform', () => ({
isNativeMobilePlatform: vi.fn(() => false),
}));
+vi.mock('@core/util/platform', async (importOriginal) => ({
+ ...(await importOriginal<typeof import('@core/util/platform')>()),
+ isTauri,
+}));
vi.mock('@core/util/cookies', () => ({ syncLoginStorage: vi.fn() }));
vi.mock('@graphql-cache/lifecycle', () => ({
clearRegisteredCaches: vi.fn(async () => {}),
@@ -52,7 +59,6 @@ vi.mock('./push-registration-lifecycle', () => ({
unregisterPushRegistrationsForLogout: vi.fn(async () => {}),
}));
-import { isNativeMobilePlatform } from '@core/mobile/isNativeMobilePlatform';
import {
clearLocalDrafts,
flushLocalDrafts,
@@ -130,10 +136,13 @@ describe('logout notification cache isolation', () => {
});
describe('local draft logout warning', () => {
- it('reloads the native login document only after local cleanup and navigation', async () => {
+ // The Tauri shell, desktop included: a webview navigation to the identity
+ // provider would be handed to the system browser by the navigation plugin,
+ // leaving the app itself signed in.
+ it('reloads the Tauri login document only after local cleanup and navigation', async () => {
const order: string[] = [];
client.current = new QueryClient();
- vi.mocked(isNativeMobilePlatform).mockReturnValue(true);
+ isTauri.mockReturnValue(true);
vi.mocked(clearLocalDrafts).mockImplementationOnce(async () => {
order.push('clear');
});
@@ -143,11 +152,9 @@ describe('local draft logout warning', () => {
const reload = vi.fn(() => {
order.push('reload');
});
+ const fetchMock = vi.fn(async () => new Response());
vi.stubGlobal('window', { location: { reload } });
- vi.stubGlobal(
- 'fetch',
- vi.fn(async () => new Response())
- );
+ vi.stubGlobal('fetch', fetchMock);
const { logout, dispose } = createRoot((dispose) => ({
logout: useLogout(),
dispose,
@@ -155,11 +162,15 @@ describe('local draft logout warning', () => {
try {
await logout();
expect(order).toEqual(['clear', 'navigate', 'reload']);
+ expect(fetchMock).toHaveBeenCalledWith(
+ 'https://auth.example.com/oauth2/logout',
+ expect.objectContaining({ credentials: 'include', mode: 'no-cors' })
+ );
expect(navigate).toHaveBeenLastCalledWith('/login');
expect(reload).toHaveBeenCalledOnce();
} finally {
dispose();
- vi.mocked(isNativeMobilePlatform).mockReturnValue(false);
+ isTauri.mockReturnValue(false);
vi.mocked(authServiceClient.logout).mockClear();
vi.unstubAllGlobals();
client.current.clear();
diff --git a/apps/web/src/lib/core/auth/logout.ts b/apps/web/src/lib/core/auth/logout.ts
index 9ef68a63ed..a0a092699c 100644
--- a/apps/web/src/lib/core/auth/logout.ts
+++ b/apps/web/src/lib/core/auth/logout.ts
@@ -1,8 +1,8 @@
import { clearMcpAuthAttempts } from '@app/features/settings/mcp-auth-attempt';
import { useAnalytics } from '@app/lib/analytics/analytics-context';
import { SERVER_HOSTS } from '@core/constant/servers';
-import { isNativeMobilePlatform } from '@core/mobile/isNativeMobilePlatform';
import { syncLoginStorage } from '@core/util/cookies';
+import { isTauri } from '@core/util/platform';
import { clearPostLoginRedirect } from '@core/util/postLoginRedirect';
import { clearRegisteredCaches } from '@graphql-cache/lifecycle';
import { rotateCacheScope } from '@graphql-cache/scope';
@@ -118,7 +118,12 @@ export function useLogout() {
analytics.track('sign_out');
analytics.reset();
- if (isNativeMobilePlatform()) {
+ // The Tauri shell (desktop and mobile alike) can never navigate to the
+ // identity provider: its navigation plugin treats any off-origin URL as
+ // external and hands it to the system browser, which leaves the webview
+ // sitting on the signed-in screen. End the provider session with a
+ // background request instead and route the webview to /login in place.
+ if (isTauri()) {
await fetch(SERVER_HOSTS['auth-logout'], {
credentials: 'include',
mode: 'no-cors',