diff --git a/src/composables/auth/useCurrentUser.test.ts b/src/composables/auth/useCurrentUser.test.ts index b5657505ae6..44c2ac84888 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 86e1cc6ca80..c5f51fceb14 100644 --- a/src/composables/auth/useCurrentUser.ts +++ b/src/composables/auth/useCurrentUser.ts @@ -57,7 +57,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 2fd53b2cb57..7c8eca9f76e 100644 --- a/src/platform/auth/localWeb/localWebSession.test.ts +++ b/src/platform/auth/localWeb/localWebSession.test.ts @@ -14,7 +14,7 @@ import { reportError } from '@/platform/telemetry/reportError' vi.mock(import('@/composables/useFeatureFlags')) 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, '_') @@ -101,6 +101,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/')