Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
120 commits
Select commit Hold shift + click to select a range
c19c893
refactor(account): make hosts the single source of auth copy
MaanilVerma Sep 14, 2026
e211cd3
fix(locales): drop account-existence wording from email-already-in-use
MaanilVerma Sep 14, 2026
64ece9e
test(auth): guard cloud auth copy against account enumeration
MaanilVerma Sep 14, 2026
3aa6c3c
test(auth): address review nits on auth copy resolution
MaanilVerma Sep 14, 2026
36c5790
test(website): assert the collapsed invalid-credential line on user-n…
MaanilVerma Sep 15, 2026
c66a653
fix(website): drop the unrenderable user-not-found/wrong-password copy
MaanilVerma Sep 15, 2026
9348238
test(website): broaden the sign-in enumeration oracle to match the cl…
MaanilVerma Sep 15, 2026
b742c75
Merge branch 'main' into maanil/fe-2188-localization-sso
MaanilVerma Sep 15, 2026
7184764
fix(locales): drop the unrenderable user-not-found/wrong-password copy
MaanilVerma Sep 15, 2026
d0e3c13
Merge branch 'main' into maanil/fe-2188-localization-sso
MaanilVerma Sep 15, 2026
3633eb7
test(website): use the i18n generic-error copy after the main merge
MaanilVerma Sep 15, 2026
cea548a
Merge branch 'main' into maanil/fe-2188-localization-sso
MaanilVerma Sep 15, 2026
61b4451
fix(workspace): type the session error key against the locale shape
MaanilVerma Sep 15, 2026
b7a3541
Merge branch 'main' into maanil/fe-2188-localization-sso
MaanilVerma Sep 15, 2026
885faf4
Merge branch 'main' into maanil/fe-2188-localization-sso
MaanilVerma Sep 15, 2026
e68e3f0
Merge remote-tracking branch 'origin/main' into maanil/fe-2188-locali…
MaanilVerma Sep 15, 2026
4db1dbe
Merge remote-tracking branch 'origin/main' into maanil/fe-2191-decomp…
MaanilVerma Sep 16, 2026
d69670b
refactor(account): add pure session state transition and mint arbitra…
MaanilVerma Sep 16, 2026
7a16e1f
refactor(account): route every session commit through one transition
MaanilVerma Sep 16, 2026
6c9c0a5
refactor(account): import AccountUser from sessionContracts in identity
MaanilVerma Sep 16, 2026
d5e9fc3
refactor(account): carry commit payloads in session events and effects
MaanilVerma Sep 16, 2026
4878540
refactor(account): extract credential cache and mint coordinator from…
MaanilVerma Sep 16, 2026
3ccca0d
refactor(account): keep credential freshness policy with the cache
MaanilVerma Sep 16, 2026
d18c716
Merge remote-tracking branch 'origin/main' into maanil/fe-2196-c2-con…
MaanilVerma Sep 16, 2026
ce6d000
feat(account): construct the session client with identity and add dis…
MaanilVerma Sep 16, 2026
c265fdb
fix(account): harden the construct-with-identity tests and neutralize…
MaanilVerma Sep 16, 2026
4516673
refactor(cloud): construct the session client with identity in worksp…
MaanilVerma Sep 16, 2026
75711dc
refactor(cloud): review fixes for construct-with-identity in workspac…
MaanilVerma Sep 16, 2026
e35ef22
feat(account): lazily activated identity port
MaanilVerma Sep 16, 2026
dcc57ab
refactor(website): construct the workshop session client with a lazy …
MaanilVerma Sep 16, 2026
35d7eb4
fix(account): resolve lazy identity activation on the first delivery
MaanilVerma Sep 16, 2026
d043b0f
test(website): flag off then on never shows signed-out before Firebas…
MaanilVerma Sep 16, 2026
c723b51
fix(account): drop a lazy identity loader rejection that lands after …
MaanilVerma Sep 16, 2026
1e2216a
test(website): drive the workshop session host over the real session …
MaanilVerma Sep 16, 2026
821bdf6
refactor(account): route the expiry commit through the single commit …
MaanilVerma Sep 16, 2026
c31f4ac
Merge branch 'maanil/fe-2191-decompose-session' into maanil/fe-2196-c…
MaanilVerma Sep 16, 2026
75e3c28
Merge branch 'maanil/fe-2196-c2-construct-with-identity' into maanil/…
MaanilVerma Sep 16, 2026
9dc4b31
fix(account): guard lazy identity delivery by generation and sign out…
MaanilVerma Sep 16, 2026
f5fc42b
Merge branch 'maanil/fe-2196-c3-store-construct-with-identity' into m…
MaanilVerma Sep 16, 2026
f7e2e23
Merge remote-tracking branch 'origin/main' into maanil/fe-2191-decomp…
MaanilVerma Sep 16, 2026
e7153ec
Merge branch 'maanil/fe-2191-decompose-session' into maanil/fe-2196-c…
MaanilVerma Sep 16, 2026
7459488
Merge branch 'maanil/fe-2196-c2-construct-with-identity' into maanil/…
MaanilVerma Sep 16, 2026
f2adf68
Merge branch 'maanil/fe-2196-c3-store-construct-with-identity' into m…
MaanilVerma Sep 16, 2026
9874cfe
Merge branch 'main' into maanil/fe-2188-localization-sso
MaanilVerma Sep 16, 2026
651e277
Merge branch 'maanil/fe-2188-localization-sso' into maanil/fe-2191-de…
MaanilVerma Sep 16, 2026
59b7573
Merge branch 'maanil/fe-2191-decompose-session' into maanil/fe-2196-c…
MaanilVerma Sep 16, 2026
1b84482
Merge branch 'maanil/fe-2196-c2-construct-with-identity' into maanil/…
MaanilVerma Sep 16, 2026
8f17e4e
Merge branch 'maanil/fe-2196-c3-store-construct-with-identity' into m…
MaanilVerma Sep 16, 2026
71e38b3
refactor(account): split the session transition and mint arbitration …
MaanilVerma Sep 16, 2026
0f96221
Merge branch 'maanil/fe-2191-decompose-session' into maanil/fe-2196-c…
MaanilVerma Sep 16, 2026
d48d1f1
Merge branch 'maanil/fe-2196-c3-store-construct-with-identity' into m…
MaanilVerma Sep 16, 2026
5f7ad49
Merge branch 'maanil/fe-2196-c2-construct-with-identity' into maanil/…
MaanilVerma Sep 16, 2026
612a1bb
fix(account): tighten the popup mint to exactly one identity event
MaanilVerma Sep 16, 2026
44bbc19
perf(account): read stored credentials only when the in-memory one is…
MaanilVerma Sep 16, 2026
d65981c
fix(account): let a failed lazy identity activation retry and settle …
MaanilVerma Sep 16, 2026
84a1ca2
fix(account): detach an identity subscription disposed during its fir…
MaanilVerma Sep 16, 2026
aeb36fc
Merge branch 'maanil/fe-2191-decompose-session' into maanil/fe-2196-c…
MaanilVerma Sep 16, 2026
6699d65
Merge branch 'maanil/fe-2196-c2-construct-with-identity' into maanil/…
MaanilVerma Sep 16, 2026
709b4c8
Merge branch 'maanil/fe-2196-c3-store-construct-with-identity' into m…
MaanilVerma Sep 16, 2026
23c5bb6
test(auth): share the enumeration oracle and cover the cancelled seco…
MaanilVerma Sep 16, 2026
df8ea1d
Merge branch 'main' into maanil/fe-2188-localization-sso
MaanilVerma Sep 16, 2026
82e272e
Merge remote-tracking branch 'origin/maanil/fe-2188-localization-sso'…
MaanilVerma Sep 16, 2026
65fa927
Merge branch 'maanil/fe-2191-decompose-session' into maanil/fe-2196-c…
MaanilVerma Sep 16, 2026
eb6dd94
Merge branch 'maanil/fe-2196-c2-construct-with-identity' into maanil/…
MaanilVerma Sep 16, 2026
2e0858b
Merge branch 'maanil/fe-2196-c3-store-construct-with-identity' into m…
MaanilVerma Sep 16, 2026
448c4b9
Merge remote-tracking branch 'origin/main' into maanil/fe-2188-locali…
MaanilVerma Sep 17, 2026
52054e1
Merge branch 'maanil/fe-2188-localization-sso' into maanil/fe-2191-de…
MaanilVerma Sep 17, 2026
838ae89
Merge branch 'maanil/fe-2191-decompose-session' into maanil/fe-2196-c…
MaanilVerma Sep 17, 2026
d179a6c
Merge branch 'maanil/fe-2196-c2-construct-with-identity' into maanil/…
MaanilVerma Sep 17, 2026
eaa4428
Merge branch 'maanil/fe-2196-c3-store-construct-with-identity' into m…
MaanilVerma Sep 17, 2026
386d96d
Merge remote-tracking branch 'origin/main' into maanil/fe-2188-locali…
MaanilVerma Sep 17, 2026
1b89a09
Merge branch 'maanil/fe-2191-decompose-session' into maanil/fe-2196-c…
MaanilVerma Sep 17, 2026
ffbec33
Merge branch 'maanil/fe-2188-localization-sso' into maanil/fe-2191-de…
MaanilVerma Sep 17, 2026
ea2ac9a
Merge branch 'maanil/fe-2196-c2-construct-with-identity' into maanil/…
MaanilVerma Sep 17, 2026
2889104
Merge branch 'maanil/fe-2196-c3-store-construct-with-identity' into m…
MaanilVerma Sep 17, 2026
006f110
test(account): name the post-dispose explicit-user mint for what it does
MaanilVerma Sep 17, 2026
df6ffd7
refactor(account): name the mint guards by verdict and split the type…
MaanilVerma Sep 17, 2026
dc2ab4c
docs(account): state what lazy identity activation resolves on and th…
MaanilVerma Sep 17, 2026
19ae957
test(account): take the identity suite's fakes from the shared fixture
MaanilVerma Sep 17, 2026
d48db49
test(account): share the session test fakes from one fixture module
MaanilVerma Sep 17, 2026
c5801ad
test(cloud): model the Firebase first delivery one way and pin store …
MaanilVerma Sep 17, 2026
016f718
docs(cloud): name the construction-order dependency behind the identi…
MaanilVerma Sep 17, 2026
7306ed8
test(website): pin the lazy identity re-activation, the abandoned min…
MaanilVerma Sep 17, 2026
03bfdb7
Merge branch 'maanil/fe-2196-c3-store-construct-with-identity' into m…
MaanilVerma Sep 17, 2026
482ba49
Merge branch 'maanil/fe-2196-c2-construct-with-identity' into maanil/…
MaanilVerma Sep 17, 2026
7d1d4c7
Merge branch 'maanil/fe-2191-decompose-session' into maanil/fe-2196-c…
MaanilVerma Sep 17, 2026
37a84c2
Merge branch 'maanil/fe-2196-c3-store-construct-with-identity' into m…
MaanilVerma Sep 17, 2026
7af0afe
Merge branch 'maanil/fe-2196-c2-construct-with-identity' into maanil/…
MaanilVerma Sep 17, 2026
9826d1b
Merge remote-tracking branch 'origin/main' into maanil/fe-2188-locali…
MaanilVerma Sep 17, 2026
f8e97d4
Merge branch 'maanil/fe-2188-localization-sso' into maanil/fe-2191-de…
MaanilVerma Sep 17, 2026
4d98540
Merge branch 'maanil/fe-2191-decompose-session' into maanil/fe-2196-c…
MaanilVerma Sep 17, 2026
53db9f3
Merge branch 'maanil/fe-2196-c3-store-construct-with-identity' into m…
MaanilVerma Sep 17, 2026
ba5c637
Merge branch 'maanil/fe-2196-c2-construct-with-identity' into maanil/…
MaanilVerma Sep 17, 2026
feaeccc
test(account): split the client builder out of the data fixture and d…
MaanilVerma Sep 17, 2026
01a3b78
Merge branch 'maanil/fe-2191-decompose-session' into maanil/fe-2196-c…
MaanilVerma Sep 17, 2026
112bec2
test(account): import the scheduler buffer default instead of copying it
MaanilVerma Sep 17, 2026
83d8fb8
Merge branch 'maanil/fe-2196-c3-store-construct-with-identity' into m…
MaanilVerma Sep 17, 2026
b321250
Merge branch 'maanil/fe-2196-c2-construct-with-identity' into maanil/…
MaanilVerma Sep 17, 2026
f32024e
Merge branch 'maanil/fe-2191-decompose-session' into maanil/fe-2196-c…
MaanilVerma Sep 17, 2026
4fbdc9b
fix(account): drop a session subscriber whose first replay throws
MaanilVerma Sep 17, 2026
50580a6
Merge branch 'maanil/fe-2196-c3-store-construct-with-identity' into m…
MaanilVerma Sep 17, 2026
94b1495
Merge branch 'maanil/fe-2196-c2-construct-with-identity' into maanil/…
MaanilVerma Sep 17, 2026
6b17307
Merge branch 'maanil/fe-2191-decompose-session' into maanil/fe-2196-c…
MaanilVerma Sep 17, 2026
da83189
test(website): pin the flag-off delivery, the cache hit, and trim the…
MaanilVerma Sep 17, 2026
5b8b504
test(cloud): guard the replay port, export the settle ceiling, and ex…
MaanilVerma Sep 17, 2026
9c1a388
Merge branch 'maanil/fe-2196-c3-store-construct-with-identity' into m…
MaanilVerma Sep 17, 2026
7614f52
Merge remote-tracking branch 'origin/main' into maanil/fe-2191-decomp…
MaanilVerma Sep 17, 2026
4fa9efd
Merge branch 'maanil/fe-2191-decompose-session' into maanil/fe-2196-c…
MaanilVerma Sep 17, 2026
cb01c88
Merge branch 'maanil/fe-2196-c2-construct-with-identity' into maanil/…
MaanilVerma Sep 17, 2026
a8003b7
Merge branch 'maanil/fe-2196-c3-store-construct-with-identity' into m…
MaanilVerma Sep 17, 2026
e8b0522
test(cloud): stub firebase and vuefire in the billing subscription-ra…
MaanilVerma Sep 17, 2026
e3ef8fd
Merge branch 'maanil/fe-2196-c3-store-construct-with-identity' into m…
MaanilVerma Sep 17, 2026
2949c2e
Merge remote-tracking branch 'origin/main' into maanil/fe-2196-c2-con…
MaanilVerma Sep 17, 2026
4eea04e
Merge branch 'maanil/fe-2196-c2-construct-with-identity' into maanil/…
MaanilVerma Sep 17, 2026
c01fa5f
Merge branch 'maanil/fe-2196-c3-store-construct-with-identity' into m…
MaanilVerma Sep 17, 2026
d145c57
Merge branch 'main' into maanil/fe-2196-c3-store-construct-with-identity
MaanilVerma Sep 17, 2026
6e819ed
Merge branch 'maanil/fe-2196-c3-store-construct-with-identity' into m…
MaanilVerma Sep 17, 2026
5e57606
Merge remote-tracking branch 'origin/main' into maanil/fe-2196-c3-sto…
MaanilVerma Sep 18, 2026
549b82b
fix(cloud): fail closed when a rollback catches a unified mint parked…
MaanilVerma Sep 18, 2026
c93e823
Merge remote-tracking branch 'origin/maanil/fe-2196-c3-store-construc…
MaanilVerma Sep 18, 2026
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
27 changes: 27 additions & 0 deletions apps/website/src/config/__fixtures__/workshopSessionFakes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* The user and token-exchange fakes the workshop session suites share. A
* suite keeps the transitions it drives; only the exchange contract lives here.
*/
import { vi } from 'vitest'

import type { AccountUser } from '@comfyorg/account-core/session'

export function testUser(uid = 'uid-1'): AccountUser {
return { uid, getIdToken: vi.fn(async () => 'id-token') }
}

export function mintBody(token: string) {
return {
token,
permissions: ['workspace:read'],
expires_at: new Date(Date.now() + 90 * 60 * 1000).toISOString(),
workspace: { id: 'ws-1', name: 'Personal', type: 'personal' },
role: 'owner'
}
}

export function okFetch(token = 'jwt-1') {
return vi.fn<typeof fetch>(
async () => new Response(JSON.stringify(mintBody(token)), { status: 200 })
)
}
159 changes: 83 additions & 76 deletions apps/website/src/config/workshop-account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,73 @@ import { beforeEach, describe, expect, it, onTestFinished, vi } from 'vitest'

import type { User } from 'firebase/auth'

import type { AccountUser, SessionClient } from '@comfyorg/account-core/session'
import { createTestIdentity } from '@comfyorg/account-core/testing'

import {
captureAuthRefreshFailed,
captureAuthRefreshSucceeded
} from '../scripts/posthog'
import {
subscribeAuthRefreshTelemetry,
workshopSessionClient
} from './workshop-account'

vi.mock(import('../scripts/posthog'))

const STORAGE_KEY = 'comfy.workshop.session.v1'

function testUser(uid = 'uid-1'): AccountUser {
return { uid, getIdToken: vi.fn(async () => 'id-token') }
}

function testFirebaseUser(uid = 'uid-1'): User {
return testUser(uid) as Partial<User> as User
}

function mintBody(token: string) {
import type { LazyIdentity } from '@comfyorg/account-core/lazyIdentity'

import { okFetch, testUser } from './__fixtures__/workshopSessionFakes'
import { STORAGE_KEY } from './workshop-account'

const h = vi.hoisted(() => ({
captureSucceeded: vi.fn(),
captureFailed: vi.fn(),
firebaseEvaluated: vi.fn(),
deliver: undefined as ((user: User | null) => void) | undefined
}))

vi.mock<unknown>(import('../scripts/posthog'), () => ({
captureAuthRefreshSucceeded: h.captureSucceeded,
captureAuthRefreshFailed: h.captureFailed
}))

vi.mock<unknown>(import('./workshop-firebase'), async () => {
Comment thread
MaanilVerma marked this conversation as resolved.
Resolved
const { createTestIdentity } = await import('@comfyorg/account-core/testing')
h.firebaseEvaluated()
return {
token,
permissions: ['workspace:read'],
expires_at: new Date(Date.now() + 90 * 60 * 1000).toISOString(),
workspace: { id: 'ws-1', name: 'Personal', type: 'personal' },
role: 'owner'
workshopIdentity: createTestIdentity<User>({
onUserChanged: (callback) => {
h.deliver = callback
callback(null)
return () => {
h.deliver = undefined
}
}
})
}
}
})

function okFetch(token = 'jwt-1') {
return vi.fn<typeof fetch>(
async () => new Response(JSON.stringify(mintBody(token)), { status: 200 })
)
function testFirebaseUser(uid = 'uid-1'): User {
return testUser(uid) as Partial<User> as User
}

function statusFetch(status: number) {
return vi.fn<typeof fetch>(async () => new Response('{}', { status }))
}

async function importFresh() {
vi.resetModules()
const mod = await import('./workshop-account')
return {
client: mod.workshopSessionClient,
identity: mod.workshopIdentity,
startTelemetry: mod.subscribeAuthRefreshTelemetry
}
}

beforeEach(() => {
sessionStorage.clear()
workshopSessionClient.invalidate()
})

describe('workshop session storage adapter', () => {
it('caches the minted session and serves it back without a network call', async () => {
const first = await workshopSessionClient.ensureFresh(testUser(), {
const { client } = await importFresh()

const first = await client.ensureFresh(testUser(), {
fetchImpl: okFetch()
})
expect(first?.status).toBe('ok')
expect(sessionStorage.getItem(STORAGE_KEY)).not.toBeNull()

const secondFetch = vi.fn<typeof fetch>()
const second = await workshopSessionClient.ensureFresh(testUser(), {
const second = await client.ensureFresh(testUser(), {
fetchImpl: secondFetch
})
expect(second?.status).toBe('ok')
Expand All @@ -82,8 +90,9 @@ describe('workshop session storage adapter', () => {
throw new Error('storage disabled')
}
})
const { client } = await importFresh()

const result = await workshopSessionClient.ensureFresh(testUser(), {
const result = await client.ensureFresh(testUser(), {
fetchImpl: okFetch()
})

Expand All @@ -94,84 +103,82 @@ describe('workshop session storage adapter', () => {
})
})

describe('workshop identity', () => {
it('leaves the Firebase module unloaded until the identity is activated', async () => {
const { identity } = await importFresh()

expect(h.firebaseEvaluated).not.toHaveBeenCalled()
await identity.activate()
expect(h.firebaseEvaluated).toHaveBeenCalledOnce()
})
})

describe('auth refresh telemetry', () => {
function attachManualPort(client: SessionClient<User>) {
let deliver: ((user: User | null) => void) | undefined
onTestFinished(
client.attachIdentity(
createTestIdentity<User>({
onUserChanged: (callback) => {
deliver = callback
return () => undefined
}
})
)
)
return (user: User | null) => deliver?.(user)
async function activateIdentity(identity: LazyIdentity<User>) {
await identity.activate()
return (user: User | null) => h.deliver?.(user)
}

it('reports one succeeded outcome per minted token', async () => {
vi.stubGlobal('fetch', okFetch())
onTestFinished(subscribeAuthRefreshTelemetry())
const fire = attachManualPort(workshopSessionClient)
const { identity, startTelemetry } = await importFresh()
onTestFinished(startTelemetry())
const fire = await activateIdentity(identity)

fire(testFirebaseUser())

await vi.waitFor(() =>
expect(captureAuthRefreshSucceeded).toHaveBeenCalledOnce()
)
expect(captureAuthRefreshFailed).not.toHaveBeenCalled()
await vi.waitFor(() => expect(h.captureSucceeded).toHaveBeenCalledOnce())
expect(h.captureFailed).not.toHaveBeenCalled()
})

it('does not repeat the outcome for a cached read of the same token', async () => {
vi.stubGlobal('fetch', okFetch())
onTestFinished(subscribeAuthRefreshTelemetry())
const fire = attachManualPort(workshopSessionClient)
const { client, identity, startTelemetry } = await importFresh()
onTestFinished(startTelemetry())
const fire = await activateIdentity(identity)

fire(testFirebaseUser())
await vi.waitFor(() =>
expect(captureAuthRefreshSucceeded).toHaveBeenCalledOnce()
)
await vi.waitFor(() => expect(h.captureSucceeded).toHaveBeenCalledOnce())
fire(testFirebaseUser())
await vi.waitFor(() =>
expect(workshopSessionClient.getSnapshot().phase).toBe('authenticated')
expect(client.getSnapshot().phase).toBe('authenticated')
)

expect(
captureAuthRefreshSucceeded,
h.captureSucceeded,
'a cached read is not a new refresh outcome'
).toHaveBeenCalledOnce()
})

it('reports a permanent failure outcome', async () => {
vi.stubGlobal('fetch', statusFetch(403))
onTestFinished(subscribeAuthRefreshTelemetry())
const fire = attachManualPort(workshopSessionClient)
const { identity, startTelemetry } = await importFresh()
onTestFinished(startTelemetry())
const fire = await activateIdentity(identity)

fire(testFirebaseUser())

await vi.waitFor(() =>
expect(captureAuthRefreshFailed).toHaveBeenCalledExactlyOnceWith(
expect(h.captureFailed).toHaveBeenCalledExactlyOnceWith(
'permanent_failure'
)
)
expect(captureAuthRefreshSucceeded).not.toHaveBeenCalled()
expect(h.captureSucceeded).not.toHaveBeenCalled()
})

it('stays silent on a transient failure', async () => {
vi.stubGlobal('fetch', statusFetch(503))
onTestFinished(subscribeAuthRefreshTelemetry())
const fire = attachManualPort(workshopSessionClient)
const { client, identity, startTelemetry } = await importFresh()
onTestFinished(startTelemetry())
const fire = await activateIdentity(identity)

fire(testFirebaseUser())

await vi.waitFor(() =>
expect(workshopSessionClient.getSnapshot().phase).toBe('error')
)
await vi.waitFor(() => expect(client.getSnapshot().phase).toBe('error'))
expect(
captureAuthRefreshFailed,
h.captureFailed,
'valid-on-read has no retry machinery, so transient outcomes are cloud-only vocabulary'
).not.toHaveBeenCalled()
expect(captureAuthRefreshSucceeded).not.toHaveBeenCalled()
expect(h.captureSucceeded).not.toHaveBeenCalled()
})
})
21 changes: 16 additions & 5 deletions apps/website/src/config/workshop-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
*/
import type { User } from 'firebase/auth'

import type { LazyIdentity } from '@comfyorg/account-core/lazyIdentity'
import { createLazyIdentity } from '@comfyorg/account-core/lazyIdentity'
import type { SessionClient } from '@comfyorg/account-core/session'
import {
createSessionClient,
Expand All @@ -21,7 +23,7 @@ import {
import { createBalanceReader } from './workshop-balance'
import { WORKSHOP_CLOUD_BASE_URL } from './workshop-env'

const STORAGE_KEY = 'comfy.workshop.session.v1'
export const STORAGE_KEY = 'comfy.workshop.session.v1'

const storage = {
read(): string | null {
Expand All @@ -48,11 +50,20 @@ const storage = {
}
}

/** Activated by the session lifecycle; the Firebase chunk loads only then. */
export const workshopIdentity: LazyIdentity<User> = createLazyIdentity<User>(
() =>
import('./workshop-firebase').then((firebase) => firebase.workshopIdentity)
)

export const workshopSessionClient: SessionClient<User> =
createSessionClient<User>({
exchangeUrl: `${WORKSHOP_CLOUD_BASE_URL}/api/auth/token`,
storage
})
createSessionClient<User>(
{
exchangeUrl: `${WORKSHOP_CLOUD_BASE_URL}/api/auth/token`,
storage
},
workshopIdentity
)

export const workshopBalanceReader = createBalanceReader(
workshopSessionClient,
Expand Down
3 changes: 1 addition & 2 deletions apps/website/src/config/workshop-firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,5 @@ export function signOutWorkshop(): Promise<void> {
return identity.signOut()
}

/** Fires with the restored user (or null) once Firebase settles, then on every change. */
/** The identity the session client attaches; only the package can mint one. */
/** Reached only through workshop-account's lazy port, so this chunk stays off the flag-off path. */
export const workshopIdentity = identity
Loading
Loading