mirror of
https://github.com/vercel/commerce.git
synced 2025-05-19 07:56:59 +00:00
24 lines
509 B
TypeScript
24 lines
509 B
TypeScript
import { serialize } from 'cookie'
|
|
import type { LogoutEndpoint } from '.'
|
|
|
|
const logout: LogoutEndpoint['handlers']['logout'] = async ({
|
|
res,
|
|
body: { redirectTo },
|
|
config,
|
|
}) => {
|
|
// 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 logout
|