mirror of
https://github.com/vercel/commerce.git
synced 2025-07-25 03:01:22 +00:00
.vscode
assets
components
config
framework
bigcommerce
api
definitions
endpoints
cart
catalog
checkout
customer
login
logout
index.ts
logout.ts
signup
wishlist
fragments
operations
utils
index.ts
auth
cart
customer
lib
product
scripts
types
wishlist
.env.template
README.md
commerce.config.json
fetcher.ts
index.tsx
next.config.js
provider.ts
schema.d.ts
schema.graphql
commerce
shopify
lib
pages
public
.editorconfig
.env.template
.gitignore
.prettierignore
.prettierrc
README.md
codegen.json
commerce.config.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
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
|