Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(auth): disable graphql cache on confirmed session expiry (#8278)
Sean Aye0a9a0d958355
diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.mdindex d3fa67d7e2..4a6587d1d3 100644--- a/apps/web/AGENTS.md+++ b/apps/web/AGENTS.md@@ -67,6 +67,8 @@ Then trigger the interaction and read `window.__inst.log`. `'1,2,3' → '' → '## Development Patterns### General+- Disable GraphQL cache sessions and clear login hints on confirmed auth 401s,+ even with retained user data; preserve session state on transient failures.- Mobile dock search owns transient category/mode state in `features/command/mobile`; reuse the shared entity source and explicit full-text adapter rather than overlaying the dock query on view tabs or saved facets. See `docs/agent-guide/search.md` at the repository root.- Keep Quick Access cache availability reactive to the GraphQL rollout flag; it can arrive after the provider mounts, and email has no legacy source fallback.- Virtualize mobile name results like desktop Command Menu; local Quick Access sources are unbounded, and mounting them all stalls iOS keyboard focus during layout. Load additional search pages near the scroll end instead of reserving a paging bar.diff --git a/apps/web/src/routes/Root.tsx b/apps/web/src/routes/Root.tsxindex 5338688ab0..36a0113b46 100644--- a/apps/web/src/routes/Root.tsx+++ b/apps/web/src/routes/Root.tsx@@ -24,12 +24,7 @@ import { useHotKeyRoot } from '@core/hotkey/hotkeys';import { IosPushNotificationModal } from '@core/mobile/IosPushNotificationModal';import { IpadUnsupportedDialog } from '@core/mobile/IpadUnsupportedDialog';import { formatTabTitle, tabTitleSignal } from '@core/signal/tabTitle';-import {- getLoginCookieOptions,- setCookie,- syncLoginStorage,- updateCookie,-} from '@core/util/cookies';+import { setCookie } from '@core/util/cookies';import { fireAndForget } from '@core/util/fireAndForget';import { licenseChannel } from '@core/util/licenseUpdateBroadcastChannel';import { isTauri } from '@core/util/platform';@@ -39,12 +34,7 @@ import { MaybeTauriProvider } from '@macro/tauri';import { TauriRouteListener } from '@macro/tauri/TauriProvider';import { Telemetry } from '@macro-inc/observability';import { BrowserNotificationModal } from '@notifications';-import {- invalidateUserInfo,- prefetchUserInfo,- useUserInfoQuery,-} from '@queries/auth/user-info';-import { setGraphqlSoupSessionActive } from '@service-storage/graphql-soup';+import { invalidateUserInfo, prefetchUserInfo } from '@queries/auth/user-info';import { MetaProvider, Title } from '@solidjs/meta';import {HashRouter,@@ -64,20 +54,7 @@ import { detect } from 'detect-browser';import { createEffect, type JSX, on, onCleanup, onMount } from 'solid-js';import { AppRouterView } from './app-router-view';-/** Syncs login cookie with auth state. Only updates on successful query (not errors/loading). */-function useSyncLoginCookie() {- const userInfoQuery = useUserInfoQuery();-- createEffect(() => {- if (!userInfoQuery.isSuccess) return;-- const authenticated = userInfoQuery.data.authenticated ?? false;- const { value, ...options } = getLoginCookieOptions(authenticated);- updateCookie('login', value, options);- syncLoginStorage(authenticated);- setGraphqlSoupSessionActive(authenticated);- });-}+import { useSyncLoginCookie } from './use-sync-login-cookie';const rootPreload: RoutePreloadFunc = async (args) => {await prefetchUserInfo();diff --git a/apps/web/src/routes/use-sync-login-cookie.test.ts b/apps/web/src/routes/use-sync-login-cookie.test.tsnew file mode 100644index 0000000000..91b4889337--- /dev/null+++ b/apps/web/src/routes/use-sync-login-cookie.test.ts@@ -0,0 +1,87 @@+/** @vitest-environment jsdom */+import { hasLoginCookie, syncLoginStorage } from '@core/util/cookies';+import { ThrownResultError } from '@core/util/result';+import { setGraphqlSoupSessionActive } from '@service-storage/graphql-soup';+import { createRoot, createSignal } from 'solid-js';+import { afterEach, beforeEach, expect, it, vi } from 'vitest';+import { useSyncLoginCookie } from './use-sync-login-cookie';++const mocks = vi.hoisted(() => ({ query: vi.fn() }));+vi.mock('@queries/auth/user-info', () => ({+ useUserInfoQuery: () => mocks.query(),+}));+vi.mock('@service-storage/graphql-soup', () => ({+ setGraphqlSoupSessionActive: vi.fn(),+}));++let dispose: (() => void) | undefined;+beforeEach(() => {+ vi.clearAllMocks();+ document.cookie = 'login=true; path=/';+ syncLoginStorage(true);+});+afterEach(() => {+ dispose?.();+ document.cookie = 'login=; max-age=0; path=/';+ syncLoginStorage(false);+});++it('disables the cache and clears stale login hints on a 401 with retained identity', () => {+ const [error, setError] = createSignal<Error | null>(null);+ mocks.query.mockReturnValue({+ get error() {+ return error();+ },+ get isSuccess() {+ return error() === null;+ },+ data: { authenticated: true },+ });+ createRoot((cleanup) => {+ dispose = cleanup;+ useSyncLoginCookie();+ });+ expect(setGraphqlSoupSessionActive).toHaveBeenLastCalledWith(true);++ setError(new ThrownResultError([{ code: 'UNAUTHORIZED', message: '' }]));++ expect(setGraphqlSoupSessionActive).toHaveBeenLastCalledWith(false);+ expect(hasLoginCookie()).toBe(false);++ setError(null);+ expect(setGraphqlSoupSessionActive).toHaveBeenLastCalledWith(true);+ expect(hasLoginCookie()).toBe(true);+});++it.each([null, 'NETWORK_ERROR', 'INTERNAL_SERVER_ERROR'])(+ 'preserves the session for pending or transient auth failures: %s',+ (code) => {+ mocks.query.mockReturnValue({+ isSuccess: false,+ error: code ? new ThrownResultError([{ code, message: '' }]) : null,+ get data() {+ throw new Error('Must not read pending query data');+ },+ });+ createRoot((cleanup) => {+ dispose = cleanup;+ useSyncLoginCookie();+ });+ expect(setGraphqlSoupSessionActive).not.toHaveBeenCalled();+ expect(hasLoginCookie()).toBe(true);+ }+);++it('keeps a successful signed-out response off the cache', () => {+ mocks.query.mockReturnValue({+ isSuccess: true,+ error: null,+ data: { authenticated: false },+ });+ createRoot((cleanup) => {+ dispose = cleanup;+ useSyncLoginCookie();+ });+ expect(setGraphqlSoupSessionActive).toHaveBeenCalledWith(false);+ expect(hasLoginCookie()).toBe(false);+});diff --git a/apps/web/src/routes/use-sync-login-cookie.ts b/apps/web/src/routes/use-sync-login-cookie.tsnew file mode 100644index 0000000000..90c206816e--- /dev/null+++ b/apps/web/src/routes/use-sync-login-cookie.ts@@ -0,0 +1,33 @@+import {+ getLoginCookieOptions,+ syncLoginStorage,+ updateCookie,+} from '@core/util/cookies';+import { thrownResultErrorHasCode } from '@core/util/result';+import { useUserInfoQuery } from '@queries/auth/user-info';+import { setGraphqlSoupSessionActive } from '@service-storage/graphql-soup';+import { createEffect, on } from 'solid-js';++/** Keep session clients and login hints in sync with definitive auth results. */+export function useSyncLoginCookie() {+ const query = useUserInfoQuery();++ createEffect(+ on(+ () => {+ // A 401 wins over retained identity from a previous successful fetch.+ if (thrownResultErrorHasCode(query.error, 'UNAUTHORIZED')) return false;+ // Loading and transient failures must preserve offline session state.+ if (!query.isSuccess) return undefined;+ return query.data.authenticated ?? false;+ },+ (authenticated) => {+ if (authenticated === undefined) return;+ const { value, ...options } = getLoginCookieOptions(authenticated);+ updateCookie('login', value, options);+ syncLoginStorage(authenticated);+ setGraphqlSoupSessionActive(authenticated);+ }+ )+ );+}diff --git a/docs/agent-guide/login.md b/docs/agent-guide/login.mdindex d68b6db091..75d5d1e2ff 100644--- a/docs/agent-guide/login.md+++ b/docs/agent-guide/login.md@@ -78,6 +78,14 @@ Signed universal links and share-sheet flows still need end-to-end verification;see the [Tauri guide](../../apps/web/tauri/src-tauri/README.md#ios-27-scene-lifecycle)and [repeatable iOS smoke test](../../apps/web/tests/native/ios/README.md).+## Signed-out GraphQL regression++Open a public sharing link with stale login hints and an expired session. Once+user-info returns 401, GraphQL must use the plain network client, dispose any+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 AndroidIf a signed-out page shows the bottom `Login` / `Sign Up` banner, both buttons