Skip to content

Commit b785b33

Browse files
authored
refactor(auth): use generated OpenAPI type for customer creation (#14852)
## Summary Replace the hand-rolled `CreateCustomerPayload` in `authStore` with the generated OpenAPI `CreateCustomerRequest`, now that the comfy-api spec declares both `turnstile_token` and `signup_source`. ## Changes - **What**: `createCustomer` types its request body from `operations['createCustomer']` (the generated `@comfyorg/registry-types` contract) instead of a local interface, so the field set drift-checks against the backend at compile time. `signup_source` is always set from the client build (`DISTRIBUTION`), so the caller-facing param is `Omit<CreateCustomerRequest, 'signup_source'>` rather than a shape that advertises a field callers cannot actually set. - **Breaking**: none. Runtime behavior is unchanged (body is still `{ ...payload, signup_source: DISTRIBUTION }`). ## Review Focus Follow-up to #14528. The inline schema override is removed now that the backend regenerated types carry `turnstile_token` + `signup_source`, and the `payload` param no longer exposes the always-overwritten `signup_source`. Verified locally: `vue-tsc --noEmit` clean, `authStore.test.ts` 88/88 pass, eslint clean. ## Screenshots (if applicable)
1 parent e48b869 commit b785b33

1 file changed

Lines changed: 5 additions & 18 deletions

File tree

src/stores/authStore.ts

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import { getComfyApiBaseUrl } from '@/config/comfyApi'
2424
import { t } from '@/i18n'
2525
import { fetchWithUnifiedRemint } from '@/platform/auth/unified/remintRetry'
2626
import { DISTRIBUTION, isCloud } from '@/platform/distribution/types'
27-
import type { Distribution } from '@/platform/distribution/types'
2827
import {
2928
clearPreservedQuery,
3029
getPreservedQueryParam
@@ -46,21 +45,9 @@ type CreditPurchasePayload =
4645
operations['InitiateCreditPurchase']['requestBody']['content']['application/json']
4746
type CreateCustomerResponse =
4847
operations['createCustomer']['responses']['201']['content']['application/json']
49-
50-
/**
51-
* Request body for createCustomer. The Cloudflare Turnstile token captured at
52-
* signup is forwarded to the backend as `turnstile_token` (snake_case), which
53-
* reads this field on the CreateCustomer request; it is omitted for non-signup
54-
* flows and on OSS / localhost where Turnstile is not rendered.
55-
*
56-
* TODO: replace with the generated `operations['createCustomer']` request-body
57-
* type once the backend OpenAPI spec includes `turnstile_token`, so the field
58-
* name/optionality drift-checks against the backend at compile time.
59-
*/
60-
type CreateCustomerPayload = {
61-
turnstile_token?: string
62-
signup_source?: Distribution
63-
}
48+
type CreateCustomerPayload = NonNullable<
49+
operations['createCustomer']['requestBody']
50+
>['content']['application/json']
6451
type GetCustomerBalanceResponse =
6552
operations['GetCustomerBalance']['responses']['200']['content']['application/json']
6653
type AccessBillingPortalResponse =
@@ -392,7 +379,7 @@ export const useAuthStore = defineStore('auth', () => {
392379
}
393380

394381
const createCustomer = async (
395-
payload?: CreateCustomerPayload
382+
payload?: Omit<CreateCustomerPayload, 'signup_source'>
396383
): Promise<CreateCustomerResponse> => {
397384
const sessionUserId = currentUser.value?.uid
398385
const authHeader = await getAuthHeader()
@@ -560,7 +547,7 @@ export const useAuthStore = defineStore('auth', () => {
560547
action: (auth: Auth) => Promise<T>,
561548
options: {
562549
createCustomer?: boolean
563-
customerPayload?: CreateCustomerPayload
550+
customerPayload?: Omit<CreateCustomerPayload, 'signup_source'>
564551
} = {}
565552
): Promise<T> => {
566553
loading.value = true

0 commit comments

Comments
 (0)