4
0
forked from crowetic/commerce

Updated logout API to remove the cookie

This commit is contained in:
Luis Alvarez 2020-10-22 18:44:35 -05:00
parent c9f5babfdd
commit 1d7365bc38
3 changed files with 12 additions and 1 deletions

View File

@ -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)

View File

@ -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<BigcommerceConfigOptions, 'customerCookie'>) {
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),
}
}

View File

@ -3,6 +3,7 @@ export interface CommerceAPIConfig {
apiToken: string
cartCookie: string
cartCookieMaxAge: number
customerCookie: string
fetch<Data = any, Variables = any>(
query: string,
queryData?: CommerceAPIFetchOptions<Variables>,