mirror of
https://github.com/vercel/commerce.git
synced 2025-08-13 20:31:23 +00:00
assets
components
config
lib
bigcommerce
api
cart
catalog
customers
handlers
index.ts
login.ts
logout.ts
signup.ts
definitions
fragments
operations
utils
wishlist
checkout.ts
index.ts
cart
products
scripts
wishlist
index.tsx
schema.d.ts
schema.graphql
use-customer.tsx
use-login.tsx
use-logout.tsx
use-price.tsx
use-signup.tsx
commerce
browser.ts
colors.ts
logger.ts
range-map.ts
to-pixels.ts
pages
public
utils
.gitignore
.prettierignore
README.md
codegen.json
global.d.ts
next-env.d.ts
next.config.js
package.json
postcss.config.js
tailwind.config.js
tsconfig.json
yarn.lock
51 lines
1.2 KiB
TypeScript
51 lines
1.2 KiB
TypeScript
import createApiHandler, {
|
|
BigcommerceApiHandler,
|
|
BigcommerceHandler,
|
|
} from '../utils/create-api-handler'
|
|
import isAllowedMethod from '../utils/is-allowed-method'
|
|
import { BigcommerceApiError } from '../utils/errors'
|
|
import signup from './handlers/signup'
|
|
|
|
export type SignupBody = {
|
|
firstName: string
|
|
lastName: string
|
|
email: string
|
|
password: string
|
|
}
|
|
|
|
export type SignupHandlers = {
|
|
signup: BigcommerceHandler<null, { cartId?: string } & Partial<SignupBody>>
|
|
}
|
|
|
|
const METHODS = ['POST']
|
|
|
|
const signupApi: BigcommerceApiHandler<null, SignupHandlers> = async (
|
|
req,
|
|
res,
|
|
config,
|
|
handlers
|
|
) => {
|
|
if (!isAllowedMethod(req, res, METHODS)) return
|
|
|
|
const { cookies } = req
|
|
const cartId = cookies[config.cartCookie]
|
|
|
|
try {
|
|
const body = { ...req.body, cartId }
|
|
return await handlers['signup']({ req, res, config, body })
|
|
} catch (error) {
|
|
console.error(error)
|
|
|
|
const message =
|
|
error instanceof BigcommerceApiError
|
|
? 'An unexpected error ocurred with the Bigcommerce API'
|
|
: 'An unexpected error ocurred'
|
|
|
|
res.status(500).json({ data: null, errors: [{ message }] })
|
|
}
|
|
}
|
|
|
|
const handlers = { signup }
|
|
|
|
export default createApiHandler(signupApi, handlers, {})
|