mirror of
https://github.com/vercel/commerce.git
synced 2025-06-19 05:31:22 +00:00
chore: setup commerce & next config fix: replace all call to bigcommerce from aquilacms provider feat add validation to input in signup
31 lines
653 B
TypeScript
31 lines
653 B
TypeScript
import { serialize } from 'cookie'
|
|
import { getConfig } from '../..'
|
|
import { LogoutHandlers } from '../logout'
|
|
|
|
const logoutHandler: LogoutHandlers['logout'] = async ({
|
|
res,
|
|
body: { redirectTo },
|
|
config,
|
|
}) => {
|
|
config = getConfig(config)
|
|
|
|
await config.storeApiFetch('/v2/auth/logout', {
|
|
method: 'GET',
|
|
})
|
|
|
|
// Remove the cookie
|
|
res.setHeader(
|
|
'Set-Cookie',
|
|
serialize(config.customerCookie, '', { maxAge: -1, path: '/' })
|
|
)
|
|
|
|
// Only allow redirects to a relative URL
|
|
if (redirectTo?.startsWith('/')) {
|
|
res.redirect(redirectTo)
|
|
} else {
|
|
res.status(200).json({ data: null })
|
|
}
|
|
}
|
|
|
|
export default logoutHandler
|