Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove uneeded inflight coalescing
  • Loading branch information
benceruleanlu committed Nov 4, 2025
commit 93c3c3fce36a2653919b4d0af9f2af2a116e5e95
87 changes: 26 additions & 61 deletions src/platform/auth/session/useSessionCookie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@ import { api } from '@/scripts/api'
import { isCloud } from '@/platform/distribution/types'
import { useFirebaseAuthStore } from '@/stores/firebaseAuthStore'

/**
* Tracks the in-flight createSession request to dedupe concurrent calls.
*/
let createSessionInFlight: Promise<void> | null = null
/**
* Tracks the in-flight deleteSession request to dedupe concurrent calls.
*/
let deleteSessionInFlight: Promise<void> | null = null

/**
* Session cookie management for cloud authentication.
* Creates and deletes session cookies on the ComfyUI server.
Expand All @@ -23,40 +14,27 @@ export const useSessionCookie = () => {
const createSession = async (): Promise<void> => {
if (!isCloud) return

if (createSessionInFlight) {
await createSessionInFlight
return
}

createSessionInFlight = (async () => {
const authStore = useFirebaseAuthStore()
const authHeader = await authStore.getAuthHeader()
const authStore = useFirebaseAuthStore()
const authHeader = await authStore.getAuthHeader()

if (!authHeader) {
throw new Error('No auth header available for session creation')
}

const response = await fetch(api.apiURL('/auth/session'), {
method: 'POST',
credentials: 'include',
headers: {
...authHeader,
'Content-Type': 'application/json'
}
})
if (!authHeader) {
throw new Error('No auth header available for session creation')
}

if (!response.ok) {
const errorData = await response.json().catch(() => ({}))
throw new Error(
`Failed to create session: ${errorData.message || response.statusText}`
)
const response = await fetch(api.apiURL('/auth/session'), {
method: 'POST',
credentials: 'include',
headers: {
...authHeader,
'Content-Type': 'application/json'
}
})()
})

try {
await createSessionInFlight
} finally {
createSessionInFlight = null
if (!response.ok) {
const errorData = await response.json().catch(() => ({}))
throw new Error(
`Failed to create session: ${errorData.message || response.statusText}`
)
}
}

Expand All @@ -67,29 +45,16 @@ export const useSessionCookie = () => {
const deleteSession = async (): Promise<void> => {
if (!isCloud) return

if (deleteSessionInFlight) {
await deleteSessionInFlight
return
}

deleteSessionInFlight = (async () => {
const response = await fetch(api.apiURL('/auth/session'), {
method: 'DELETE',
credentials: 'include'
})

if (!response.ok) {
const errorData = await response.json().catch(() => ({}))
throw new Error(
`Failed to delete session: ${errorData.message || response.statusText}`
)
}
})()
const response = await fetch(api.apiURL('/auth/session'), {
method: 'DELETE',
credentials: 'include'
})

try {
await deleteSessionInFlight
} finally {
deleteSessionInFlight = null
if (!response.ok) {
const errorData = await response.json().catch(() => ({}))
throw new Error(
`Failed to delete session: ${errorData.message || response.statusText}`
)
}
}

Expand Down