mirror of
https://github.com/vercel/commerce.git
synced 2025-08-06 08:51:25 +00:00
assets
components
config
docs
framework
bigcommerce
api
cart
catalog
customers
handlers
index.ts
login.ts
logout.ts
signup.ts
definitions
fragments
utils
wishlist
checkout.ts
index.ts
auth
cart
common
customer
lib
product
scripts
wishlist
README.md
index.tsx
provider.tsx
schema.d.ts
schema.graphql
types.ts
commerce
lib
pages
public
.editorconfig
.env.template
.gitignore
.prettierignore
CHANGELOG.md
README.md
codegen.json
global.d.ts
license.md
next-env.d.ts
next.config.js
package.json
postcss.config.js
tailwind.config.js
tsconfig.json
yarn.lock
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import createApiHandler, {
|
|
BigcommerceApiHandler,
|
|
BigcommerceHandler,
|
|
} from '../utils/create-api-handler'
|
|
import isAllowedMethod from '../utils/is-allowed-method'
|
|
import { BigcommerceApiError } from '../utils/errors'
|
|
import logout from './handlers/logout'
|
|
|
|
export type LogoutHandlers = {
|
|
logout: BigcommerceHandler<null, { redirectTo?: string }>
|
|
}
|
|
|
|
const METHODS = ['GET']
|
|
|
|
const logoutApi: BigcommerceApiHandler<null, LogoutHandlers> = async (
|
|
req,
|
|
res,
|
|
config,
|
|
handlers
|
|
) => {
|
|
if (!isAllowedMethod(req, res, METHODS)) return
|
|
|
|
try {
|
|
const redirectTo = req.query.redirect_to
|
|
const body = typeof redirectTo === 'string' ? { redirectTo } : {}
|
|
|
|
return await handlers['logout']({ 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 = { logout }
|
|
|
|
export default createApiHandler(logoutApi, handlers, {})
|