diff --git a/lib/bigcommerce/api/customers/handlers/logout.ts b/lib/bigcommerce/api/customers/handlers/logout.ts index 9446262e2..937ce0954 100644 --- a/lib/bigcommerce/api/customers/handlers/logout.ts +++ b/lib/bigcommerce/api/customers/handlers/logout.ts @@ -1,3 +1,4 @@ +import { serialize } from 'cookie' import { LogoutHandlers } from '../logout' const logoutHandler: LogoutHandlers['logout'] = async ({ @@ -5,6 +6,12 @@ const logoutHandler: LogoutHandlers['logout'] = async ({ 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) diff --git a/lib/bigcommerce/api/index.ts b/lib/bigcommerce/api/index.ts index 69e26f523..1ab33756c 100644 --- a/lib/bigcommerce/api/index.ts +++ b/lib/bigcommerce/api/index.ts @@ -66,9 +66,12 @@ if (!(STORE_API_URL && STORE_API_TOKEN && STORE_API_CLIENT_ID)) { export class Config { private config: BigcommerceConfig - constructor(config: BigcommerceConfigOptions) { + constructor(config: Omit) { this.config = { ...config, + // The customerCookie is not customizable for now, BC sets the cookie and it's + // not important to rename it + customerCookie: 'SHOP_TOKEN', imageVariables: this.getImageVariables(config.images), } } diff --git a/lib/commerce/api/index.ts b/lib/commerce/api/index.ts index db55e1daa..ae1e3f46b 100644 --- a/lib/commerce/api/index.ts +++ b/lib/commerce/api/index.ts @@ -3,6 +3,7 @@ export interface CommerceAPIConfig { apiToken: string cartCookie: string cartCookieMaxAge: number + customerCookie: string fetch( query: string, queryData?: CommerceAPIFetchOptions,