From 98260864a5e2bb5a6150a8b35a43e7ec642b08ee Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Fri, 2 Oct 2026 17:22:41 -0400 Subject: [PATCH 1/3] feat(cloud): sign out of all devices on the web session --- .../dialog/content/setting/UserPanel.test.ts | 71 +++++++++++++++++++ .../dialog/content/setting/UserPanel.vue | 13 ++-- src/locales/en/main.json | 6 ++ .../auth/session/cloudWebSessionStore.ts | 30 +++++++- .../components/SignOutEverywhereButton.vue | 54 ++++++++++++++ src/platform/auth/webSessionFlagOn.test.ts | 57 +++++++++++++++ 6 files changed, 223 insertions(+), 8 deletions(-) create mode 100644 src/platform/auth/session/components/SignOutEverywhereButton.vue diff --git a/src/components/dialog/content/setting/UserPanel.test.ts b/src/components/dialog/content/setting/UserPanel.test.ts index 6384e63b80c..b1b66f16d00 100644 --- a/src/components/dialog/content/setting/UserPanel.test.ts +++ b/src/components/dialog/content/setting/UserPanel.test.ts @@ -5,8 +5,12 @@ import { computed, defineComponent } from 'vue' import { createI18n } from 'vue-i18n' import { createMemoryHistory, createRouter } from 'vue-router' +import type { WebSessionCommandResult } from '@comfyorg/account-core/webSession' + import { useCurrentUser } from '@/composables/auth/useCurrentUser' import enMessages from '@/locales/en/main.json' with { type: 'json' } +import { useCloudWebSessionStore } from '@/platform/auth/session/cloudWebSessionStore' +import { useToastStore } from '@/platform/updates/common/toastStore' import { useDialogService } from '@/services/dialogService' import UserPanel from './UserPanel.vue' @@ -100,3 +104,70 @@ describe('UserPanel update password', () => { expect(location.assign).not.toHaveBeenCalled() }) }) + +describe('UserPanel sign out of all devices', () => { + const signOutEverywhere = { name: 'Sign out of all devices' } + + function onWebSession(revokeAll: WebSessionCommandResult) { + const webSession = useCloudWebSessionStore() + vi.spyOn(webSession, 'isActive').mockReturnValue(true) + return vi + .spyOn(webSession, 'revokeAllSessions') + .mockResolvedValue(revokeAll) + } + + it.for([ + { name: 'the web session is off', sessionOn: false, firebaseLogin: true }, + { + name: 'the tab has no Firebase login to prove identity', + sessionOn: true, + firebaseLogin: false + } + ])('renders nothing when $name', async ({ sessionOn, firebaseLogin }) => { + signInAsEmailUser({ hasFirebaseLogin: firebaseLogin }) + vi.spyOn(useCloudWebSessionStore(), 'isActive').mockReturnValue(sessionOn) + await renderPanel() + + expect(screen.getByRole('button', { name: 'Log Out' })).toBeVisible() + expect(screen.queryByRole('button', signOutEverywhere)).toBeNull() + }) + + it('revokes every session once, then signs this tab out', async () => { + signInAsEmailUser({ hasFirebaseLogin: true }) + const revokeAll = onWebSession({ status: 'ok' }) + await renderPanel() + + await userEvent.click(screen.getByRole('button', signOutEverywhere)) + + expect(revokeAll).toHaveBeenCalledOnce() + expect(useCurrentUser().handleSignOut).toHaveBeenCalledOnce() + expect(useToastStore().messagesToAdd).toEqual([ + expect.objectContaining({ + severity: 'success', + summary: 'Signed out of all devices' + }) + ]) + }) + + it('keeps the user signed in and shows why when the revoke fails', async () => { + signInAsEmailUser({ hasFirebaseLogin: true }) + onWebSession({ + status: 'error', + code: 'SESSION_UNAVAILABLE', + retryable: true + }) + await renderPanel() + + await userEvent.click(screen.getByRole('button', signOutEverywhere)) + + expect(useCurrentUser().handleSignOut).not.toHaveBeenCalled() + expect(useToastStore().messagesToAdd).toEqual([ + expect.objectContaining({ + severity: 'error', + summary: "Couldn't sign out of all devices", + detail: enMessages.auth.webSession.token.unavailable + }) + ]) + expect(screen.getByRole('button', signOutEverywhere)).toBeEnabled() + }) +}) diff --git a/src/components/dialog/content/setting/UserPanel.vue b/src/components/dialog/content/setting/UserPanel.vue index 6a8ecde39b2..09b45f99429 100644 --- a/src/components/dialog/content/setting/UserPanel.vue +++ b/src/components/dialog/content/setting/UserPanel.vue @@ -55,10 +55,13 @@
- +
+ + +
= new Set([ 'NO_SESSION', 'IDENTITY_CHANGED' @@ -285,7 +293,7 @@ export const useCloudWebSessionStore = defineStore('cloudWebSession', () => { } throw new WebSessionTokenError( error, - t(TOKEN_FAILURE_COPY[failure.code]) + webSessionFailureMessage(failure.code) ) } } @@ -317,6 +325,21 @@ export const useCloudWebSessionStore = defineStore('cloudWebSession', () => { }) } + async function revokeAllSessions(): Promise { + const session = currentSession() + const user = firebaseIdentity.currentUser() + if (!session || !user) { + return { status: 'error', code: 'NO_SESSION', retryable: false } + } + return revokeAllWebSessions(sessionOptions(), session.csrfToken, () => + user.getIdToken() + ).catch(() => ({ + status: 'error', + code: 'SESSION_UNAVAILABLE', + retryable: true + })) + } + function currentSession(): WebSession | undefined { const state = identity?.getState() if (state?.phase !== 'signed_in') return undefined @@ -412,6 +435,7 @@ export const useCloudWebSessionStore = defineStore('cloudWebSession', () => { whenSessionCreated: () => creating, whenDecided, signedInInteractively, - signOut + signOut, + revokeAllSessions } }) diff --git a/src/platform/auth/session/components/SignOutEverywhereButton.vue b/src/platform/auth/session/components/SignOutEverywhereButton.vue new file mode 100644 index 00000000000..72094d5adba --- /dev/null +++ b/src/platform/auth/session/components/SignOutEverywhereButton.vue @@ -0,0 +1,54 @@ + + + diff --git a/src/platform/auth/webSessionFlagOn.test.ts b/src/platform/auth/webSessionFlagOn.test.ts index b404265b77f..74e7c4fec21 100644 --- a/src/platform/auth/webSessionFlagOn.test.ts +++ b/src/platform/auth/webSessionFlagOn.test.ts @@ -217,6 +217,11 @@ function installServer( session: initial, requests: [] as SessionRequest[], dropPosts: false, + revokeAllStatus: 200, + revokeAllRequests: [] as { + authorization: string | null + csrf: string | null + }[], featureReads: [] as { credentials: RequestCredentials | null client: string | null @@ -252,6 +257,20 @@ function installServer( return answerRead() } + const answerRevokeAll = (init: RequestInit | undefined): Response => { + const headers = new Headers(init?.headers) + server.revokeAllRequests.push({ + authorization: headers.get('authorization'), + csrf: headers.get('x-csrf-token') + }) + if (server.revokeAllStatus !== 200) { + const error = { code: 'unavailable', message: 'down' } + return jsonResponse(error, server.revokeAllStatus) + } + server.session = 'revoked' + return jsonResponse({ revoked: 2 }) + } + const answerFeatures = (init: RequestInit | undefined): Response => { const client = new Headers(init?.headers).get('x-comfy-client') const credentials = init?.credentials ?? null @@ -274,6 +293,9 @@ function installServer( const url = new URL(String(input), location.href) const method = (init?.method ?? 'GET').toUpperCase() if (url.pathname === '/api/features') return answerFeatures(init) + if (url.pathname === '/api/auth/sessions/revoke-all') { + return answerRevokeAll(init) + } if (url.pathname !== '/api/auth/session') { return jsonResponse({ id: 'customer-1' }, 201) } @@ -399,6 +421,41 @@ describe('cloud app on the shared web session (unified_web_session on)', () => { expect(firebaseSignOut).toHaveBeenCalledTimes(signsOutLocally ? 1 : 0) }) + it.for([ + { name: 'ok revokes every session', status: 200, result: { status: 'ok' } }, + { + name: 'a server failure is returned, not thrown', + status: 503, + result: { status: 'error', code: 'SESSION_UNAVAILABLE' } + } + ])('revoke-all: $name', async ({ status, result }) => { + const server = installServer({ userId: 'user-a' }) + server.revokeAllStatus = status + await refreshRemoteConfig({ useAuth: false }) + identity.signIn(USER_A) + await useSessionCookie().ensureSessionCookie() + const webSession = useCloudWebSessionStore() + + expect(await webSession.revokeAllSessions()).toMatchObject(result) + expect(server.revokeAllRequests).toEqual([ + { authorization: 'Bearer firebase-id-token', csrf: 'csrf-user-a' } + ]) + }) + + it('revoke-all sends nothing without a Firebase login to prove identity', async () => { + const server = installServer({ userId: 'user-a' }) + await refreshRemoteConfig({ useAuth: false }) + await useSessionCookie().ensureSessionCookie() + const webSession = useCloudWebSessionStore() + expect(webSession.state.phase).toBe('signed_in') + + expect(await webSession.revokeAllSessions()).toMatchObject({ + status: 'error', + code: 'NO_SESSION' + }) + expect(server.revokeAllRequests).toEqual([]) + }) + it('resets the tab and tells the user when another account takes the session', async () => { const server = installServer({ userId: 'user-a' }) await refreshRemoteConfig({ useAuth: false }) From 20040f6ce10413f6cf47759a4735b5ddc3d22f7e Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Fri, 2 Oct 2026 17:42:07 -0400 Subject: [PATCH 2/3] fix(cloud): show sign out of all devices only while the web session is signed in --- .../dialog/content/setting/UserPanel.test.ts | 55 +++++++++++++++++-- .../components/SignOutEverywhereButton.vue | 2 +- 2 files changed, 50 insertions(+), 7 deletions(-) diff --git a/src/components/dialog/content/setting/UserPanel.test.ts b/src/components/dialog/content/setting/UserPanel.test.ts index b1b66f16d00..a68e27530b1 100644 --- a/src/components/dialog/content/setting/UserPanel.test.ts +++ b/src/components/dialog/content/setting/UserPanel.test.ts @@ -1,3 +1,4 @@ +import { fromPartial } from '@total-typescript/shoehorn' import userEvent from '@testing-library/user-event' import { render, screen } from '@testing-library/vue' import { beforeEach, describe, expect, it, vi } from 'vitest' @@ -5,18 +6,28 @@ import { computed, defineComponent } from 'vue' import { createI18n } from 'vue-i18n' import { createMemoryHistory, createRouter } from 'vue-router' +import type { FirebaseIdentity } from '@comfyorg/account-core/firebase' import type { WebSessionCommandResult } from '@comfyorg/account-core/webSession' +import type { WebSessionIdentityState } from '@comfyorg/account-core/webSessionIdentity' import { useCurrentUser } from '@/composables/auth/useCurrentUser' import enMessages from '@/locales/en/main.json' with { type: 'json' } import { useCloudWebSessionStore } from '@/platform/auth/session/cloudWebSessionStore' import { useToastStore } from '@/platform/updates/common/toastStore' +import { api } from '@/scripts/api' import { useDialogService } from '@/services/dialogService' import UserPanel from './UserPanel.vue' vi.mock(import('@/composables/auth/useCurrentUser')) vi.mock(import('@/services/dialogService')) +vi.mock(import('@/platform/auth/firebaseIdentity'), () => ({ + firebaseIdentity: fromPartial({ + onUserChanged: () => () => {}, + onTokenChanged: () => () => {}, + currentUser: () => null + }) +})) const i18n = createI18n({ legacy: false, @@ -108,24 +119,56 @@ describe('UserPanel update password', () => { describe('UserPanel sign out of all devices', () => { const signOutEverywhere = { name: 'Sign out of all devices' } + beforeEach(() => { + vi.spyOn(api, 'reconnectSocket').mockResolvedValue() + }) + + const signedInSession: WebSessionIdentityState = { + phase: 'signed_in', + session: { + user: { + id: 'user-a', + email: 'user-a@example.com', + emailVerified: true, + signInProvider: 'google.com' + }, + csrfToken: 'csrf-user-a', + expiresAt: Date.now() + 86_400_000, + absoluteExpiresAt: Date.now() + 604_800_000 + } + } + function onWebSession(revokeAll: WebSessionCommandResult) { const webSession = useCloudWebSessionStore() - vi.spyOn(webSession, 'isActive').mockReturnValue(true) + webSession.state = signedInSession return vi .spyOn(webSession, 'revokeAllSessions') .mockResolvedValue(revokeAll) } - it.for([ - { name: 'the web session is off', sessionOn: false, firebaseLogin: true }, + it.for<{ + name: string + session: WebSessionIdentityState + firebaseLogin: boolean + }>([ + { + name: 'the web session is off', + session: { phase: 'idle' }, + firebaseLogin: true + }, + { + name: 'the web session is signed out', + session: { phase: 'signed_out', outcome: 'signed_out' }, + firebaseLogin: true + }, { name: 'the tab has no Firebase login to prove identity', - sessionOn: true, + session: signedInSession, firebaseLogin: false } - ])('renders nothing when $name', async ({ sessionOn, firebaseLogin }) => { + ])('renders nothing when $name', async ({ session, firebaseLogin }) => { signInAsEmailUser({ hasFirebaseLogin: firebaseLogin }) - vi.spyOn(useCloudWebSessionStore(), 'isActive').mockReturnValue(sessionOn) + useCloudWebSessionStore().state = session await renderPanel() expect(screen.getByRole('button', { name: 'Log Out' })).toBeVisible() diff --git a/src/platform/auth/session/components/SignOutEverywhereButton.vue b/src/platform/auth/session/components/SignOutEverywhereButton.vue index 72094d5adba..23bd0779c1e 100644 --- a/src/platform/auth/session/components/SignOutEverywhereButton.vue +++ b/src/platform/auth/session/components/SignOutEverywhereButton.vue @@ -1,6 +1,6 @@