mirror of
https://github.com/vercel/commerce.git
synced 2025-07-25 11:11:24 +00:00
implement account-tied carts and cart reconciliation
Signed-off-by: Loan Laux <loan@outgrow.io>
This commit is contained in:
@@ -1,24 +0,0 @@
|
||||
import { getConfig, ReactionCommerceConfig } from '../api'
|
||||
import getCustomerIdQuery from '../utils/queries/get-customer-id-query'
|
||||
import Cookies from 'js-cookie'
|
||||
|
||||
async function getCustomerId({
|
||||
customerToken: customerAccesToken,
|
||||
config,
|
||||
}: {
|
||||
customerToken: string
|
||||
config?: ReactionCommerceConfig
|
||||
}): Promise<number | undefined> {
|
||||
config = getConfig(config)
|
||||
|
||||
const { data } = await config.fetch(getCustomerIdQuery, {
|
||||
variables: {
|
||||
customerAccesToken:
|
||||
customerAccesToken || Cookies.get(config.customerCookie),
|
||||
},
|
||||
})
|
||||
|
||||
return data.customer?.id
|
||||
}
|
||||
|
||||
export default getCustomerId
|
26
framework/reactioncommerce/customer/get-viewer-id.ts
Normal file
26
framework/reactioncommerce/customer/get-viewer-id.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { getConfig, ReactionCommerceConfig } from '../api'
|
||||
import getViewerIdQuery from '../utils/queries/get-customer-id-query'
|
||||
|
||||
async function getViewerId({
|
||||
customerToken: customerAccessToken,
|
||||
config,
|
||||
}: {
|
||||
customerToken: string
|
||||
config?: ReactionCommerceConfig
|
||||
}): Promise<number | undefined> {
|
||||
config = getConfig(config)
|
||||
|
||||
const { data } = await config.fetch(
|
||||
getViewerIdQuery,
|
||||
{},
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${customerAccessToken}`,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
return data.viewer?._id
|
||||
}
|
||||
|
||||
export default getViewerId
|
Reference in New Issue
Block a user