commerce/packages/kibocommerce/src/api/utils/get-customer-id.ts
Catalin Pinte d1d9e8c434
Fix auth & wishlist (#918)
* Fix auth & wishlist

* Revert files

* Update signup.ts

* Update signup.ts

* Requested changes

* Revert fetch options
2023-01-30 10:50:25 -05:00

25 lines
656 B
TypeScript

import type { KiboCommerceConfig } from '..'
import { getCustomerAccountQuery } from '../queries/get-customer-account-query'
async function getCustomerId({
customerToken,
config,
}: {
customerToken: string
config: KiboCommerceConfig
}): Promise<string | undefined> {
const token = customerToken
? Buffer.from(customerToken, 'base64').toString('ascii')
: null
const accessToken = token ? JSON.parse(token).accessToken : null
const { data } = await config.fetch(getCustomerAccountQuery, undefined, {
headers: {
'x-vol-user-claims': accessToken,
},
})
return data?.customerAccount?.id
}
export default getCustomerId