mirror of
https://github.com/vercel/commerce.git
synced 2025-05-17 15:06:59 +00:00
Add ordercloud logout
This commit is contained in:
parent
dc3a981dc0
commit
b18973dfb3
@ -9,15 +9,17 @@ import customer from './customer'
|
|||||||
import customerCard from './customer/card'
|
import customerCard from './customer/card'
|
||||||
import customerAddress from './customer/address'
|
import customerAddress from './customer/address'
|
||||||
import signup from './signup'
|
import signup from './signup'
|
||||||
|
import logout from './logout'
|
||||||
|
|
||||||
const endpoints = {
|
const endpoints = {
|
||||||
cart,
|
cart,
|
||||||
checkout,
|
checkout,
|
||||||
|
logout: logout,
|
||||||
|
signup: signup,
|
||||||
customer: customer,
|
customer: customer,
|
||||||
'customer/card': customerCard,
|
'customer/card': customerCard,
|
||||||
'customer/address': customerAddress,
|
'customer/address': customerAddress,
|
||||||
'catalog/products': products,
|
'catalog/products': products,
|
||||||
signup: signup,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function ordercloudAPI(commerce: OrdercloudAPI) {
|
export default function ordercloudAPI(commerce: OrdercloudAPI) {
|
||||||
|
18
packages/ordercloud/src/api/endpoints/logout/index.ts
Normal file
18
packages/ordercloud/src/api/endpoints/logout/index.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import { GetAPISchema, createEndpoint } from '@vercel/commerce/api'
|
||||||
|
import logoutEndpoint from '@vercel/commerce/api/endpoints/logout'
|
||||||
|
import type { LogoutSchema } from '@vercel/commerce/types/logout'
|
||||||
|
import type { OrdercloudAPI } from '../..'
|
||||||
|
import logout from './logout'
|
||||||
|
|
||||||
|
export type LogoutAPI = GetAPISchema<OrdercloudAPI, LogoutSchema>
|
||||||
|
|
||||||
|
export type LogoutEndpoint = LogoutAPI['endpoint']
|
||||||
|
|
||||||
|
export const handlers: LogoutEndpoint['handlers'] = { logout }
|
||||||
|
|
||||||
|
const logoutApi = createEndpoint<LogoutAPI>({
|
||||||
|
handler: logoutEndpoint,
|
||||||
|
handlers,
|
||||||
|
})
|
||||||
|
|
||||||
|
export default logoutApi
|
25
packages/ordercloud/src/api/endpoints/logout/logout.ts
Normal file
25
packages/ordercloud/src/api/endpoints/logout/logout.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import { serialize } from 'cookie'
|
||||||
|
import type { LogoutEndpoint } from '.'
|
||||||
|
|
||||||
|
const logout: LogoutEndpoint['handlers']['logout'] = async ({
|
||||||
|
body: { redirectTo },
|
||||||
|
config,
|
||||||
|
}) => {
|
||||||
|
const headers = {
|
||||||
|
'Set-Cookie': serialize(config.tokenCookie, '', {
|
||||||
|
maxAge: -1,
|
||||||
|
path: '/',
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
|
||||||
|
return redirectTo
|
||||||
|
? {
|
||||||
|
redirectTo,
|
||||||
|
headers,
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
headers,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default logout
|
Loading…
x
Reference in New Issue
Block a user