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(auth): reload native sign-out onto the login screen (#9248)

Peter Chinman63f4f87927b7
diff --git a/apps/web/src/lib/core/auth/logout.test.ts b/apps/web/src/lib/core/auth/logout.test.ts
index be3dea598b..a57cd28eea 100644
--- a/apps/web/src/lib/core/auth/logout.test.ts
+++ b/apps/web/src/lib/core/auth/logout.test.ts
@@ -4,10 +4,9 @@ import { isCancelledError, QueryClient } from '@tanstack/solid-query';
import { createRoot } from 'solid-js';
import { describe, expect, it, vi } from 'vitest';
-const { client, isTauri, navigate } = vi.hoisted(() => ({
+const { client, isTauri } = vi.hoisted(() => ({
client: { current: undefined as QueryClient | undefined },
isTauri: vi.fn(() => false),
- navigate: vi.fn(),
}));
vi.mock('@queries/client', () => ({
queryPersistence: {
@@ -22,7 +21,6 @@ vi.mock('@queries/client', () => ({
vi.mock('@app/lib/analytics/analytics-context', () => ({
useAnalytics: () => ({ track: vi.fn(), reset: vi.fn() }),
}));
-vi.mock('@solidjs/router', () => ({ useNavigate: () => navigate }));
vi.mock('@ui', () => ({ confirmDialog: vi.fn(async () => false) }));
vi.mock('@queries/email/local-drafts', () => ({
clearLocalDrafts: vi.fn(async () => {}),
@@ -167,21 +165,28 @@ describe('local draft logout warning', () => {
// 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 () => {
+ // The router writes a navigation's URL only once its transition settles, so
+ // the login URL must already be in place when the reload starts.
+ it('reloads the Tauri webview onto the login route after local cleanup', async () => {
const order: string[] = [];
client.current = new QueryClient();
isTauri.mockReturnValue(true);
vi.mocked(clearLocalDrafts).mockImplementationOnce(async () => {
order.push('clear');
});
- navigate.mockImplementationOnce(() => {
- order.push('navigate');
- });
- const reload = vi.fn(() => {
- order.push('reload');
- });
+ const location = {
+ hash: '#/home',
+ reload: vi.fn(() => {
+ order.push(`reload ${location.hash}`);
+ }),
+ };
+ const replaceState = vi.fn(
+ (_state: unknown, _unused: string, url: string) => {
+ location.hash = url;
+ }
+ );
const fetchMock = vi.fn(async () => new Response());
- vi.stubGlobal('window', { location: { reload } });
+ vi.stubGlobal('window', { location, history: { replaceState } });
vi.stubGlobal('fetch', fetchMock);
const { logout, dispose } = createRoot((dispose) => ({
logout: useLogout(),
@@ -189,13 +194,12 @@ describe('local draft logout warning', () => {
}));
try {
await logout();
- expect(order).toEqual(['clear', 'navigate', 'reload']);
+ expect(order).toEqual(['clear', 'reload #/login']);
expect(fetchMock).toHaveBeenCalledWith(
'https://auth.example.com/oauth2/logout',
expect.objectContaining({ credentials: 'include', mode: 'no-cors' })
);
- expect(navigate).toHaveBeenLastCalledWith('/login');
- expect(reload).toHaveBeenCalledOnce();
+ expect(location.reload).toHaveBeenCalledOnce();
} finally {
dispose();
isTauri.mockReturnValue(false);
diff --git a/apps/web/src/lib/core/auth/logout.ts b/apps/web/src/lib/core/auth/logout.ts
index 033dd22768..3938755333 100644
--- a/apps/web/src/lib/core/auth/logout.ts
+++ b/apps/web/src/lib/core/auth/logout.ts
@@ -32,7 +32,6 @@ import {
} from '@service-storage/graphql-soup';
import { raceTimeout } from '@solid-primitives/promise';
import { createCallback } from '@solid-primitives/rootless';
-import { useNavigate } from '@solidjs/router';
import { confirmDialog } from '@ui';
import { getOwner } from 'solid-js';
import { clearComposerStorage } from './clear-composer-storage';
@@ -89,7 +88,6 @@ export async function clearLocalAuthSession(
export function useLogout() {
const analytics = useAnalytics();
- const navigate = useNavigate();
const owner = getOwner();
return createCallback(async () => {
@@ -161,7 +159,10 @@ export function useLogout() {
mode: 'no-cors',
redirect: 'manual',
}).catch(() => {});
- navigate('/login');
+ // Write the login URL directly: the router commits a navigation only
+ // after its transition settles, which lands after the reload has
+ // already restarted the signed-in route with no session to load.
+ window.history.replaceState(null, '', '#/login');
// Native login reuses this WebView. End the document lifetime so queued
// editor callbacks can never adopt the next account's draft session.
reloadApp('logout');
diff --git a/docs/agent-guide/login.md b/docs/agent-guide/login.md
index 78949b3c48..b4c793126d 100644
--- a/docs/agent-guide/login.md
+++ b/docs/agent-guide/login.md
@@ -137,6 +137,14 @@ normalized cache and live-update session, and clear the login hints. Repeat with
retained user-info data from an earlier successful request. A network failure or
5xx must not end the session; successful sign-in must re-enable eligible caching.
+## Native sign-out
+
+In the desktop, iOS, and Android apps, Sign out reloads the webview onto the
+sign-in screen. The reloaded document must start on `#/login`, never on the
+route it signed out from: that route has no session left to load and shows
+loading placeholders indefinitely. Sign out from Settings → Account and from
+Home, and check that `native_webview_started` reports a `#/login` URL.
+
## Native Android
If a signed-out page shows the bottom `Login` / `Sign Up` banner, both buttons