Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/composables/auth/useCurrentUser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof mockAuthState.currentUser>
Expand Down
2 changes: 1 addition & 1 deletion src/composables/auth/useCurrentUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 9 additions & 1 deletion src/platform/auth/desktopHost/desktopHostAuthBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ComfyDesktop2AuthState, { status: 'signed_in' }>
| (DesktopHostSignedIn & { name?: string })

/** `switchWorkspace` is absent on Desktop builds before Comfy-Desktop #1671. */
export type DesktopHostAuthBridge = Omit<
Expand Down
5 changes: 3 additions & 2 deletions src/platform/auth/desktopHost/desktopHostSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
interface DesktopHostUser {
id: string
email?: string
name?: string
workspaceId?: string
}

Expand All @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions src/platform/auth/localWeb/accessTokenIdentity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
workspace_id: z.string().optional()
})

export interface AccessTokenIdentity {
userId: string
email?: string
name?: string
workspaceId?: string
}

Expand Down Expand Up @@ -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 }
}
3 changes: 2 additions & 1 deletion src/platform/auth/localWeb/localWebSession.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, '_')
Expand Down Expand Up @@ -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/')
Expand Down
Loading