From 1d7365bc38e59ed5b90c11c0c40d259be3f1b36f Mon Sep 17 00:00:00 2001 From: Luis Alvarez Date: Thu, 22 Oct 2020 18:44:35 -0500 Subject: [PATCH] Updated logout API to remove the cookie --- lib/bigcommerce/api/customers/handlers/logout.ts | 7 +++++++ lib/bigcommerce/api/index.ts | 5 ++++- lib/commerce/api/index.ts | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) 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,