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): keep the login hint through hosted Google sign-in on the web (#8604)

gbirmanac4276b5d03e
diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.md
index 9a705b6527..b0ec5e6039 100644
--- a/apps/web/AGENTS.md
+++ b/apps/web/AGENTS.md
@@ -109,6 +109,9 @@ ownership. Cancel, logout, and the ten-minute timeout retire pending callbacks.
and distinguish unresolved identity from confirmed sign-out in UI prompts.
- Probe identity on deploy-preview origins even without a local login hint;
shared HttpOnly dev cookies are not visible to JavaScript or localStorage.
+- Leave the login hint (`syncLoginStorage(true)`) before a full-page hosted
+ SSO redirect; the callback sets only HttpOnly cookies, and a load without the
+ hint never checks identity, so the returning user sees sign-in again.
- Disable GraphQL cache sessions and clear login hints on confirmed auth 401s,
even with retained user data; preserve session state on transient failures.
- Treat a repeated worker-ready frame as a coordinator restart: retire the old
diff --git a/apps/web/src/features/auth/useSsoLogin.test.ts b/apps/web/src/features/auth/useSsoLogin.test.ts
index c0cc34126b..d2dabd2460 100644
--- a/apps/web/src/features/auth/useSsoLogin.test.ts
+++ b/apps/web/src/features/auth/useSsoLogin.test.ts
@@ -17,6 +17,7 @@ const mocks = vi.hoisted(() => ({
initEmailLink: vi.fn(),
setPostLoginRedirect: vi.fn(),
toastFailure: vi.fn(),
+ syncLoginStorage: vi.fn(),
}));
vi.mock('@app/lib/analytics/analytics-context', () => ({
@@ -47,6 +48,9 @@ vi.mock('@core/email-link', () => ({
vi.mock('@core/util/fetchWithToken', () => ({
unsetTokenPromise: mocks.unsetTokenPromise,
}));
+vi.mock('@core/util/cookies', () => ({
+ syncLoginStorage: mocks.syncLoginStorage,
+}));
vi.mock('@queries/auth/user-info', () => ({
invalidateAllAfterLogin: mocks.invalidateAllAfterLogin,
}));
@@ -103,6 +107,9 @@ describe('useSsoLogin', () => {
expect(mocks.track).toHaveBeenCalledWith('login', { method: 'google' }, [
'posthog',
]);
+ // The hosted return sets only HttpOnly cookies; without this hint the
+ // returning load never checks identity and shows sign-in again.
+ expect(mocks.syncLoginStorage).toHaveBeenCalledWith(true);
});
it('preserves the original browser destination through proxy SSO', async () => {
@@ -158,6 +165,8 @@ describe('useSsoLogin', () => {
expect(mocks.track).toHaveBeenCalledWith('login', { method: 'google' }, [
'posthog',
]);
+ // The session-code redemption enables the identity check itself.
+ expect(mocks.syncLoginStorage).not.toHaveBeenCalled();
}
);
@@ -218,6 +227,7 @@ describe('useSsoLogin', () => {
expect(mocks.invalidateAllAfterLogin).toHaveBeenCalledOnce();
expect(mocks.initEmailLink).toHaveBeenCalledOnce();
expect(window.location.href).toBe(loginUrl);
+ expect(mocks.syncLoginStorage).not.toHaveBeenCalled();
}
);
});
diff --git a/apps/web/src/features/auth/useSsoLogin.ts b/apps/web/src/features/auth/useSsoLogin.ts
index 3063f92029..5666ccfd65 100644
--- a/apps/web/src/features/auth/useSsoLogin.ts
+++ b/apps/web/src/features/auth/useSsoLogin.ts
@@ -10,6 +10,7 @@ import { SERVER_HOSTS } from '@core/constant/servers';
import { useEmailLinks } from '@core/email-link';
import { isNativeMobilePlatform } from '@core/mobile/isNativeMobilePlatform';
import type { RedirectLocation } from '@core/util/authRedirect';
+import { syncLoginStorage } from '@core/util/cookies';
import { unsetTokenPromise } from '@core/util/fetchWithToken';
import { isPlatform } from '@core/util/platform';
import { setPostLoginRedirect } from '@core/util/postLoginRedirect';
@@ -146,6 +147,11 @@ export function useSsoLogin(opts?: { signupMode?: boolean }) {
analytics.track(analyticsEvent, { method: idp_name }, analyticsProviders);
+ // The hosted callback sets only HttpOnly cookies, which the app cannot
+ // see, and the return load probes identity only behind the login hint.
+ // Leave the hint now so that load checks the new session instead of
+ // showing sign-in again; a sign-in that did not complete 401s and clears it.
+ syncLoginStorage(true);
window.location.href = authUrl.toString();
};
}