mirror of
https://github.com/vercel/commerce.git
synced 2025-08-23 09:11:23 +00:00
.vscode
assets
components
config
framework
bigcommerce
commerce
elasticpath
local
ordercloud
saleor
shopify
api
endpoints
catalog
checkout
get-checkout.ts
index.ts
customer
cart.ts
login.ts
logout.ts
signup.ts
wishlist.ts
operations
utils
index.ts
auth
cart
checkout
customer
product
types
utils
wishlist
.env.template
README.md
codegen.json
commerce.config.json
const.ts
fetcher.ts
index.tsx
next.config.js
provider.ts
schema.d.ts
schema.graphql
swell
vendure
lib
pages
public
.editorconfig
.env.template
.eslintrc
.gitignore
.prettierignore
.prettierrc
Dockerfile
README.md
codegen.bigcommerce.json
codegen.json
commerce.config.json
docker-compose.yml
global.d.ts
license.md
next-env.d.ts
next.config.js
package.json
postcss.config.js
pre-push
swell-js.d.ts
tailwind.config.js
tsconfig.json
yarn.lock
39 lines
989 B
TypeScript
39 lines
989 B
TypeScript
import {
|
|
SHOPIFY_CHECKOUT_ID_COOKIE,
|
|
SHOPIFY_CHECKOUT_URL_COOKIE,
|
|
SHOPIFY_CUSTOMER_TOKEN_COOKIE,
|
|
} from '../../../const'
|
|
import associateCustomerWithCheckoutMutation from '../../../utils/mutations/associate-customer-with-checkout'
|
|
import type { CheckoutEndpoint } from '.'
|
|
|
|
const getCheckout: CheckoutEndpoint['handlers']['getCheckout'] = async ({
|
|
req,
|
|
res,
|
|
config,
|
|
}) => {
|
|
const { cookies } = req
|
|
const checkoutUrl = cookies[SHOPIFY_CHECKOUT_URL_COOKIE]
|
|
const customerCookie = cookies[SHOPIFY_CUSTOMER_TOKEN_COOKIE]
|
|
|
|
if (customerCookie) {
|
|
try {
|
|
await config.fetch(associateCustomerWithCheckoutMutation, {
|
|
variables: {
|
|
checkoutId: cookies[SHOPIFY_CHECKOUT_ID_COOKIE],
|
|
customerAccessToken: cookies[SHOPIFY_CUSTOMER_TOKEN_COOKIE],
|
|
},
|
|
})
|
|
} catch (error) {
|
|
console.error(error)
|
|
}
|
|
}
|
|
|
|
if (checkoutUrl) {
|
|
res.redirect(checkoutUrl)
|
|
} else {
|
|
res.redirect('/cart')
|
|
}
|
|
}
|
|
|
|
export default getCheckout
|