mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-01-26 19:09:52 +00:00
[API Node] Fix credits fetch condition (#3575)
This commit is contained in:
@@ -45,6 +45,7 @@ export const useFirebaseAuthStore = defineStore('firebaseAuth', () => {
|
||||
const currentUser = ref<User | null>(null)
|
||||
const isInitialized = ref(false)
|
||||
const customerCreated = ref(false)
|
||||
const isFetchingBalance = ref(false)
|
||||
|
||||
// Balance state
|
||||
const balance = ref<GetCustomerBalanceResponse | null>(null)
|
||||
@@ -95,33 +96,42 @@ export const useFirebaseAuthStore = defineStore('firebaseAuth', () => {
|
||||
}
|
||||
|
||||
const fetchBalance = async (): Promise<GetCustomerBalanceResponse | null> => {
|
||||
const token = await getIdToken()
|
||||
if (!token) {
|
||||
error.value = 'Cannot fetch balance: User not authenticated'
|
||||
return null
|
||||
}
|
||||
|
||||
const response = await fetch(`${API_BASE_URL}/customers/balance`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`
|
||||
}
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
if (response.status === 404) {
|
||||
// Customer not found is expected for new users
|
||||
isFetchingBalance.value = true
|
||||
try {
|
||||
const token = await getIdToken()
|
||||
if (!token) {
|
||||
error.value = 'Cannot fetch balance: User not authenticated'
|
||||
isFetchingBalance.value = false
|
||||
return null
|
||||
}
|
||||
const errorData = await response.json()
|
||||
error.value = `Failed to fetch balance: ${errorData.message}`
|
||||
return null
|
||||
}
|
||||
|
||||
const balanceData = await response.json()
|
||||
// Update the last balance update time
|
||||
lastBalanceUpdateTime.value = new Date()
|
||||
balance.value = balanceData
|
||||
return balanceData
|
||||
const response = await fetch(`${API_BASE_URL}/customers/balance`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`
|
||||
}
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
if (response.status === 404) {
|
||||
// Customer not found is expected for new users
|
||||
return null
|
||||
}
|
||||
const errorData = await response.json()
|
||||
error.value = `Failed to fetch balance: ${errorData.message}`
|
||||
return null
|
||||
}
|
||||
|
||||
const balanceData = await response.json()
|
||||
// Update the last balance update time
|
||||
lastBalanceUpdateTime.value = new Date()
|
||||
balance.value = balanceData
|
||||
return balanceData
|
||||
} catch (e) {
|
||||
error.value = `Failed to fetch balance: ${e}`
|
||||
return null
|
||||
} finally {
|
||||
isFetchingBalance.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const createCustomer = async (
|
||||
@@ -303,6 +313,7 @@ export const useFirebaseAuthStore = defineStore('firebaseAuth', () => {
|
||||
isInitialized,
|
||||
balance,
|
||||
lastBalanceUpdateTime,
|
||||
isFetchingBalance,
|
||||
|
||||
// Getters
|
||||
isAuthenticated,
|
||||
|
||||
Reference in New Issue
Block a user