From 8c612631c28613d3ef56e962fbcb7cb211e8f1f6 Mon Sep 17 00:00:00 2001 From: Dante Date: Wed, 28 Oct 2026 19:15:10 +0000 Subject: [PATCH] FE-3099 fix(auth): show the account name a host session's token carries (#22155) ## Summary QA L14 on the local SSO plan: with a local web SSO session the account menu shows "User" instead of the account name. Root cause: host sessions (local web SSO and Desktop) get their identity from the OAuth access token, which carries `email` but no name, and `useCurrentUser` deliberately shows no display name for them (#20536, so the email is not repeated as the name). There was nothing to show. https://github.com/Comfy-Org/cloud/pull/16878 adds an optional `name` claim to OAuth access tokens, from the same `users.name` the web session returns. This reads it: `readAccessTokenIdentity` takes `name`, the host session keeps it on its user, and `userDisplayName` shows it for host sessions. A token without the claim (before the cloud change ships, or an account with no name) still shows "User" with the email under it, as today. `DesktopHostAuthState` widens the Desktop bridge's signed-in state with an optional `name` so Desktop can pass the same claim later. ## Verification - Unit: `useCurrentUser` shows a host account by the name its session carries; the existing "without repeating the email as the name" case still passes. `startLocalWebSession` carries the token's `name` through to the host user. `src/platform/auth` + `src/composables/auth`: 657 passing. - End to end needs the cloud change on staging; until then the menu is unchanged ("User" + email), which this PR keeps. --- src/composables/auth/useCurrentUser.test.ts | 21 +++++++++++++++++++ src/composables/auth/useCurrentUser.ts | 2 +- .../auth/desktopHost/desktopHostAuthBridge.ts | 10 ++++++++- .../auth/desktopHost/desktopHostSession.ts | 5 +++-- .../auth/localWeb/accessTokenIdentity.ts | 6 ++++-- .../auth/localWeb/localWebSession.test.ts | 3 ++- 6 files changed, 40 insertions(+), 7 deletions(-) diff --git a/src/composables/auth/useCurrentUser.test.ts b/src/composables/auth/useCurrentUser.test.ts index 12cfbdd6dd5..61d7a5a6c53 100644 --- a/src/composables/auth/useCurrentUser.test.ts +++ b/src/composables/auth/useCurrentUser.test.ts @@ -100,6 +100,27 @@ describe('useCurrentUser', () => { expect(userDisplayName.value).toBeUndefined() }) + it('shows a host account by the name its session carries', async () => { + const signedIn = { + status: 'signed_in', + userId: 'host-user', + email: 'sso@example.com', + name: 'Denys Puziak' + } as const + await startDesktopHostSession({ + getState: async () => signedIn, + getWorkspaceToken: async () => 'host-token', + requestSignIn: async () => signedIn, + signOut: async () => ({ status: 'signed_out' }), + onChanged: () => () => {} + }) + + const { userDisplayName, userEmail } = useCurrentUser() + + expect(userDisplayName.value).toBe('Denys Puziak') + expect(userEmail.value).toBe('sso@example.com') + }) + it('reads a Firebase-only login entirely from Firebase', () => { mockAuthState.currentUser = fromPartial< NonNullable diff --git a/src/composables/auth/useCurrentUser.ts b/src/composables/auth/useCurrentUser.ts index a79caa86a5b..81e6c3f6b99 100644 --- a/src/composables/auth/useCurrentUser.ts +++ b/src/composables/auth/useCurrentUser.ts @@ -58,7 +58,7 @@ export const useCurrentUser = () => { } const userDisplayName = computed(() => { - if (desktopHostUser.value) return undefined + if (desktopHostUser.value) return desktopHostUser.value.name if (isApiKeyLogin.value) { return apiKeyStore.currentUser?.name } diff --git a/src/platform/auth/desktopHost/desktopHostAuthBridge.ts b/src/platform/auth/desktopHost/desktopHostAuthBridge.ts index 60d11d5a801..41c19b2c3b9 100644 --- a/src/platform/auth/desktopHost/desktopHostAuthBridge.ts +++ b/src/platform/auth/desktopHost/desktopHostAuthBridge.ts @@ -3,7 +3,15 @@ import type { ComfyDesktop2AuthState } from '@comfyorg/comfyui-desktop-bridge-types' -export type DesktopHostAuthState = ComfyDesktop2AuthState +type DesktopHostSignedIn = Extract< + ComfyDesktop2AuthState, + { status: 'signed_in' } +> + +/** A signed-in state may also carry the account's display name. */ +export type DesktopHostAuthState = + | Exclude + | (DesktopHostSignedIn & { name?: string }) /** `switchWorkspace` is absent on Desktop builds before Comfy-Desktop #1671. */ export type DesktopHostAuthBridge = Omit< diff --git a/src/platform/auth/desktopHost/desktopHostSession.ts b/src/platform/auth/desktopHost/desktopHostSession.ts index 5d8c1663ef8..7348a613c30 100644 --- a/src/platform/auth/desktopHost/desktopHostSession.ts +++ b/src/platform/auth/desktopHost/desktopHostSession.ts @@ -8,6 +8,7 @@ import type { interface DesktopHostUser { id: string email?: string + name?: string workspaceId?: string } @@ -26,8 +27,8 @@ let revision = 0 function toSession(state: DesktopHostAuthState): DesktopHostSession { if (state.status === 'disabled') return { status: 'inactive' } if (state.status === 'signed_out') return { status: 'signed_out' } - const { userId, email, workspaceId } = state - return { status: 'signed_in', user: { id: userId, email, workspaceId } } + const { userId, email, name, workspaceId } = state + return { status: 'signed_in', user: { id: userId, email, name, workspaceId } } } function apply(state: DesktopHostAuthState): void { diff --git a/src/platform/auth/localWeb/accessTokenIdentity.ts b/src/platform/auth/localWeb/accessTokenIdentity.ts index 4e8f27406a6..28a7e6af07d 100644 --- a/src/platform/auth/localWeb/accessTokenIdentity.ts +++ b/src/platform/auth/localWeb/accessTokenIdentity.ts @@ -3,12 +3,14 @@ import { z } from 'zod' const zClaims = z.object({ sub: z.string().min(1), email: z.string().optional(), + name: z.string().optional(), workspace_id: z.string().optional() }) export interface AccessTokenIdentity { userId: string email?: string + name?: string workspaceId?: string } @@ -36,6 +38,6 @@ export function readAccessTokenIdentity( } const claims = zClaims.safeParse(decoded) if (!claims.success) return undefined - const { sub, email, workspace_id } = claims.data - return { userId: sub, email, workspaceId: workspace_id } + const { sub, email, name, workspace_id } = claims.data + return { userId: sub, email, name, workspaceId: workspace_id } } diff --git a/src/platform/auth/localWeb/localWebSession.test.ts b/src/platform/auth/localWeb/localWebSession.test.ts index e4db0361030..4dfe0f4034e 100644 --- a/src/platform/auth/localWeb/localWebSession.test.ts +++ b/src/platform/auth/localWeb/localWebSession.test.ts @@ -15,7 +15,7 @@ vi.mock(import('@/composables/useFeatureFlags')) vi.mock(import('@/platform/telemetry/reportError')) const ACCESS_TOKEN = `e30.${btoa( - JSON.stringify({ sub: 'user-1', workspace_id: 'ws-1' }) + JSON.stringify({ sub: 'user-1', name: 'Ada Lovelace', workspace_id: 'ws-1' }) ) .replace(/\+/g, '-') .replace(/\//g, '_') @@ -102,6 +102,7 @@ describe('startLocalWebSession', () => { expect(desktopHostUser.value).toEqual({ id: 'user-1', email: undefined, + name: 'Ada Lovelace', workspaceId: 'ws-1' }) expect(page.url).toBe('http://localhost:8188/')