mirror of
https://github.com/vercel/commerce.git
synced 2025-07-23 04:36:49 +00:00
Handle checkout for logged in users (#405)
* create a jwt token if there is a customerId, move the get customer id to the main utils folder. Need to add in more value to the env file. Updated the env sample. * remove yarn.lock and tsconfig.json * remove build settings * remove build settings * remove build settings * Update tsconfig.json * Delete package-lock.json * fix typescript errors * Update tsconfig.json Co-authored-by: George Fitzgibbons <george.fitzgibbons@c02zw1aqlvdn.lan>
This commit is contained in:
committed by
GitHub
parent
a314893f62
commit
166bb037e4
32
framework/bigcommerce/api/utils/get-customer-id.ts
Normal file
32
framework/bigcommerce/api/utils/get-customer-id.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import type { GetCustomerIdQuery } from '../../schema'
|
||||
import type { BigcommerceConfig } from '../'
|
||||
|
||||
export const getCustomerIdQuery = /* GraphQL */ `
|
||||
query getCustomerId {
|
||||
customer {
|
||||
entityId
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
async function getCustomerId({
|
||||
customerToken,
|
||||
config,
|
||||
}: {
|
||||
customerToken: string
|
||||
config: BigcommerceConfig
|
||||
}): Promise<string | undefined> {
|
||||
const { data } = await config.fetch<GetCustomerIdQuery>(
|
||||
getCustomerIdQuery,
|
||||
undefined,
|
||||
{
|
||||
headers: {
|
||||
cookie: `${config.customerCookie}=${customerToken}`,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
return String(data?.customer?.entityId)
|
||||
}
|
||||
|
||||
export default getCustomerId
|
Reference in New Issue
Block a user