1
0
mirror of https://github.com/vercel/commerce.git synced 2025-07-25 19:21:23 +00:00
Files
commerce/pkg/storefront-data-hooks/api/operations/get-customer-id.ts
2020-10-27 06:05:38 -05:00

35 lines
666 B
TypeScript

import { GetCustomerIdQuery } from '../../schema'
import { BigcommerceConfig, getConfig } from '..'
export const getCustomerIdQuery = /* GraphQL */ `
query getCustomerId {
customer {
entityId
}
}
`
async function getCustomerId({
customerToken,
config,
}: {
customerToken: string
config?: BigcommerceConfig
}): Promise<number | undefined> {
config = getConfig(config)
const { data } = await config.fetch<GetCustomerIdQuery>(
getCustomerIdQuery,
undefined,
{
headers: {
cookie: `${config.customerCookie}=${customerToken}`,
},
}
)
return data?.customer?.entityId
}
export default getCustomerId