forked from crowetic/commerce
.vscode
assets
components
config
docs
framework
bigcommerce
api
auth
cart
common
customer
get-customer-id.ts
get-customer-wishlist.ts
index.ts
use-customer.tsx
lib
product
scripts
wishlist
.env.template
README.md
commerce.config.json
fetcher.ts
index.tsx
next.config.js
provider.ts
schema.d.ts
schema.graphql
types.ts
commerce
shopify
lib
pages
public
scripts
.editorconfig
.env.template
.gitignore
.prettierignore
README.md
codegen.json
commerce.config.json
global.d.ts
license.md
next-env.d.ts
next.config.js
package.json
postcss.config.js
tailwind.config.js
tsconfig.json
yarn.lock
35 lines
667 B
TypeScript
35 lines
667 B
TypeScript
import { GetCustomerIdQuery } from '../schema'
|
|
import { BigcommerceConfig, getConfig } from '../api'
|
|
|
|
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
|