commerce/framework/shopify/customer/get-customer-id.ts
2021-04-29 21:58:46 +03:00

28 lines
675 B
TypeScript

import { getConfig, ShopifyConfig } from '../api'
import getCustomerIdQuery from '../utils/queries/get-customer-id-query'
import Cookies from 'js-cookie'
import { GetCustomerIdQuery } from '../schema'
async function getCustomerId({
customerToken: customerAccesToken,
config,
}: {
customerToken: string
config?: ShopifyConfig
}): Promise<string | undefined> {
config = getConfig(config)
const {
data: { customer },
} = await config.fetch<GetCustomerIdQuery>(getCustomerIdQuery, {
variables: {
customerAccesToken:
customerAccesToken || Cookies.get(config.customerCookie),
},
})
return customer?.id
}
export default getCustomerId