[backport core/1.40] fix: use getAuthHeader for API key auth in subscription/billing (#9148)

Backport of #9142 to `core/1.40`

Automatically created by backport workflow.

┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-9148-backport-core-1-40-fix-use-getAuthHeader-for-API-key-auth-in-subscription-billing-3116d73d3650816f9facc4359d6a7431)
by [Unito](https://www.unito.io)

Co-authored-by: Christian Byrne <cbyrne@comfy.org>
This commit is contained in:
Comfy Org PR Bot
2026-02-24 12:00:53 +09:00
committed by GitHub
parent f0fbb55a0a
commit 3e97dde185
6 changed files with 33 additions and 12 deletions

View File

@@ -16,7 +16,7 @@ const mockAccessBillingPortal = vi.fn()
const mockReportError = vi.fn()
const mockTrackBeginCheckout = vi.fn()
const mockUserId = ref<string | undefined>('user-123')
const mockGetFirebaseAuthHeader = vi.fn(() =>
const mockGetAuthHeader = vi.fn(() =>
Promise.resolve({ Authorization: 'Bearer test-token' })
)
const mockGetCheckoutAttribution = vi.hoisted(() => vi.fn(() => ({})))
@@ -58,7 +58,7 @@ vi.mock('@/composables/useErrorHandling', () => ({
vi.mock('@/stores/firebaseAuthStore', () => ({
useFirebaseAuthStore: () =>
reactive({
getFirebaseAuthHeader: mockGetFirebaseAuthHeader,
getAuthHeader: mockGetAuthHeader,
userId: computed(() => mockUserId.value)
}),
FirebaseAuthStoreError: class extends Error {}

View File

@@ -108,7 +108,7 @@ vi.mock('@/services/dialogService', () => ({
vi.mock('@/stores/firebaseAuthStore', () => ({
useFirebaseAuthStore: vi.fn(() => ({
getFirebaseAuthHeader: mockGetAuthHeader,
getAuthHeader: mockGetAuthHeader,
get userId() {
return mockUserId.value
}
@@ -363,6 +363,27 @@ describe('useSubscription', () => {
})
})
describe('non-cloud environments', () => {
it('should not fetch subscription status when not on cloud', async () => {
mockIsCloud.value = false
mockIsLoggedIn.value = true
useSubscriptionWithScope()
await vi.dynamicImportSettled()
expect(global.fetch).not.toHaveBeenCalled()
})
it('should report isActiveSubscription as true when not on cloud', () => {
mockIsCloud.value = false
const { isActiveSubscription } = useSubscriptionWithScope()
expect(isActiveSubscription.value).toBe(true)
})
})
describe('action handlers', () => {
it('should open usage history URL', () => {
const windowOpenSpy = vi

View File

@@ -40,7 +40,7 @@ function useSubscriptionInternal() {
const { showSubscriptionRequiredDialog } = useDialogService()
const firebaseAuthStore = useFirebaseAuthStore()
const { getFirebaseAuthHeader } = firebaseAuthStore
const { getAuthHeader } = firebaseAuthStore
const { wrapWithErrorHandlingAsync } = useErrorHandling()
const { isLoggedIn } = useCurrentUser()
@@ -184,7 +184,7 @@ function useSubscriptionInternal() {
* @returns Subscription status or null if no subscription exists
*/
async function fetchSubscriptionStatus(): Promise<CloudSubscriptionStatusResponse | null> {
const authHeader = await getFirebaseAuthHeader()
const authHeader = await getAuthHeader()
if (!authHeader) {
throw new FirebaseAuthStoreError(t('toastMessages.userNotAuthenticated'))
}
@@ -217,7 +217,7 @@ function useSubscriptionInternal() {
watch(
() => isLoggedIn.value,
async (loggedIn) => {
if (loggedIn) {
if (loggedIn && isCloud) {
try {
await fetchSubscriptionStatus()
} catch (error) {
@@ -238,7 +238,7 @@ function useSubscriptionInternal() {
const initiateSubscriptionCheckout =
async (): Promise<CloudSubscriptionCheckoutResponse> => {
const authHeader = await getFirebaseAuthHeader()
const authHeader = await getAuthHeader()
if (!authHeader) {
throw new FirebaseAuthStoreError(
t('toastMessages.userNotAuthenticated')

View File

@@ -39,7 +39,7 @@ vi.mock('@/platform/telemetry', () => ({
vi.mock('@/stores/firebaseAuthStore', () => ({
useFirebaseAuthStore: vi.fn(() =>
reactive({
getFirebaseAuthHeader: mockGetAuthHeader,
getAuthHeader: mockGetAuthHeader,
userId: computed(() => mockUserId.value)
})
),

View File

@@ -54,7 +54,7 @@ export async function performSubscriptionCheckout(
const firebaseAuthStore = useFirebaseAuthStore()
const { userId } = storeToRefs(firebaseAuthStore)
const telemetry = useTelemetry()
const authHeader = await firebaseAuthStore.getFirebaseAuthHeader()
const authHeader = await firebaseAuthStore.getAuthHeader()
if (!authHeader) {
throw new FirebaseAuthStoreError(t('toastMessages.userNotAuthenticated'))

View File

@@ -239,7 +239,7 @@ export const useFirebaseAuthStore = defineStore('firebaseAuth', () => {
const fetchBalance = async (): Promise<GetCustomerBalanceResponse | null> => {
isFetchingBalance.value = true
try {
const authHeader = await getFirebaseAuthHeader()
const authHeader = await getAuthHeader()
if (!authHeader) {
throw new FirebaseAuthStoreError(
t('toastMessages.userNotAuthenticated')
@@ -435,7 +435,7 @@ export const useFirebaseAuthStore = defineStore('firebaseAuth', () => {
const addCredits = async (
requestBodyContent: CreditPurchasePayload
): Promise<CreditPurchaseResponse> => {
const authHeader = await getFirebaseAuthHeader()
const authHeader = await getAuthHeader()
if (!authHeader) {
throw new FirebaseAuthStoreError(t('toastMessages.userNotAuthenticated'))
}
@@ -475,7 +475,7 @@ export const useFirebaseAuthStore = defineStore('firebaseAuth', () => {
const accessBillingPortal = async (
targetTier?: BillingPortalTargetTier
): Promise<AccessBillingPortalResponse> => {
const authHeader = await getFirebaseAuthHeader()
const authHeader = await getAuthHeader()
if (!authHeader) {
throw new FirebaseAuthStoreError(t('toastMessages.userNotAuthenticated'))
}