forked from crowetic/commerce
Updated logout API to remove the cookie
This commit is contained in:
parent
c9f5babfdd
commit
1d7365bc38
@ -1,3 +1,4 @@
|
|||||||
|
import { serialize } from 'cookie'
|
||||||
import { LogoutHandlers } from '../logout'
|
import { LogoutHandlers } from '../logout'
|
||||||
|
|
||||||
const logoutHandler: LogoutHandlers['logout'] = async ({
|
const logoutHandler: LogoutHandlers['logout'] = async ({
|
||||||
@ -5,6 +6,12 @@ const logoutHandler: LogoutHandlers['logout'] = async ({
|
|||||||
body: { redirectTo },
|
body: { redirectTo },
|
||||||
config,
|
config,
|
||||||
}) => {
|
}) => {
|
||||||
|
// Remove the cookie
|
||||||
|
res.setHeader(
|
||||||
|
'Set-Cookie',
|
||||||
|
serialize(config.customerCookie, '', { maxAge: -1, path: '/' })
|
||||||
|
)
|
||||||
|
|
||||||
// Only allow redirects to a relative URL
|
// Only allow redirects to a relative URL
|
||||||
if (redirectTo?.startsWith('/')) {
|
if (redirectTo?.startsWith('/')) {
|
||||||
res.redirect(redirectTo)
|
res.redirect(redirectTo)
|
||||||
|
@ -66,9 +66,12 @@ if (!(STORE_API_URL && STORE_API_TOKEN && STORE_API_CLIENT_ID)) {
|
|||||||
export class Config {
|
export class Config {
|
||||||
private config: BigcommerceConfig
|
private config: BigcommerceConfig
|
||||||
|
|
||||||
constructor(config: BigcommerceConfigOptions) {
|
constructor(config: Omit<BigcommerceConfigOptions, 'customerCookie'>) {
|
||||||
this.config = {
|
this.config = {
|
||||||
...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),
|
imageVariables: this.getImageVariables(config.images),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ export interface CommerceAPIConfig {
|
|||||||
apiToken: string
|
apiToken: string
|
||||||
cartCookie: string
|
cartCookie: string
|
||||||
cartCookieMaxAge: number
|
cartCookieMaxAge: number
|
||||||
|
customerCookie: string
|
||||||
fetch<Data = any, Variables = any>(
|
fetch<Data = any, Variables = any>(
|
||||||
query: string,
|
query: string,
|
||||||
queryData?: CommerceAPIFetchOptions<Variables>,
|
queryData?: CommerceAPIFetchOptions<Variables>,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user