mirror of
https://github.com/vercel/commerce.git
synced 2025-06-19 21:51:21 +00:00
saleor: attach checkout to customer
This commit is contained in:
parent
96f79e348c
commit
3e72dfcb6e
@ -9,7 +9,7 @@ import {
|
||||
MutationTokenCreateArgs,
|
||||
} from '../schema'
|
||||
import useLogin, { UseLogin } from '@commerce/auth/use-login'
|
||||
import { setCSRFToken, setToken, throwUserErrors } from '../utils'
|
||||
import { setCSRFToken, setToken, throwUserErrors, checkoutAttach, getCheckoutId } from '../utils'
|
||||
|
||||
export default useLogin as UseLogin<typeof handler>
|
||||
|
||||
@ -40,6 +40,14 @@ export const handler: MutationHook<null, {}, MutationTokenCreateArgs> = {
|
||||
if (token && csrfToken) {
|
||||
setToken(token)
|
||||
setCSRFToken(csrfToken)
|
||||
|
||||
const { checkoutId } = getCheckoutId();
|
||||
checkoutAttach(fetch, {
|
||||
variables: { checkoutId },
|
||||
headers: {
|
||||
Authorization: `JWT ${token}`
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return null
|
||||
|
16
framework/saleor/utils/checkout-attach.ts
Normal file
16
framework/saleor/utils/checkout-attach.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import * as mutation from './mutations'
|
||||
import { CheckoutCustomerAttach } from '../schema'
|
||||
|
||||
export const checkoutAttach = async (
|
||||
fetch: any,
|
||||
{ variables, headers }: any,
|
||||
): Promise<CheckoutCustomerAttach> => {
|
||||
const data = await fetch({
|
||||
query: mutation.AttachCheckout,
|
||||
variables,
|
||||
headers
|
||||
})
|
||||
|
||||
return data;
|
||||
}
|
||||
|
@ -5,10 +5,14 @@ export { default as getSearchVariables } from './get-search-variables'
|
||||
export { default as getVendors } from './get-vendors'
|
||||
export { default as getCategories } from './get-categories'
|
||||
export { default as getCheckoutId } from './get-checkout-id'
|
||||
|
||||
export { default as checkoutCreate } from './checkout-create'
|
||||
export { checkoutAttach } from './checkout-attach';
|
||||
|
||||
export { default as checkoutToCart } from './checkout-to-cart'
|
||||
export { default as handleLogin, handleAutomaticLogin } from './handle-login'
|
||||
export { default as throwUserErrors } from './throw-user-errors'
|
||||
|
||||
export * from './queries'
|
||||
export * from './mutations'
|
||||
export * from './normalize'
|
||||
|
@ -1,5 +1,5 @@
|
||||
export const checkoutCustomerAttach = /* GraphQl */ `
|
||||
mutation associateCustomerWithCheckout($checkoutId: ID!) {
|
||||
export const AttachCheckout = /* GraphQl */ `
|
||||
mutation AttachCheckout($checkoutId: ID!) {
|
||||
checkoutCustomerAttach(checkoutId: $checkoutId) {
|
||||
errors {
|
||||
message
|
@ -5,3 +5,4 @@ export { checkoutLineUpdate } from './checkout-line-item-update'
|
||||
export { checkoutLineDelete } from './checkout-line-item-remove'
|
||||
export { sessionCreate } from './customer-access-token-create'
|
||||
export { sessionDestroy } from './customer-access-token-delete'
|
||||
export { AttachCheckout } from './attach-checkout'
|
||||
|
Loading…
x
Reference in New Issue
Block a user