commerce/providers/swell/utils/customer-token.ts
Loui Nissen-Petersen 03dcf96fb1 rename folder
2021-07-16 16:58:03 +02:00

22 lines
522 B
TypeScript

import Cookies, { CookieAttributes } from 'js-cookie'
import { SWELL_COOKIE_EXPIRE, SWELL_CUSTOMER_TOKEN_COOKIE } from '../const'
export const getCustomerToken = () => Cookies.get(SWELL_CUSTOMER_TOKEN_COOKIE)
export const setCustomerToken = (
token: string | null,
options?: CookieAttributes
) => {
if (!token) {
Cookies.remove(SWELL_CUSTOMER_TOKEN_COOKIE)
} else {
Cookies.set(
SWELL_CUSTOMER_TOKEN_COOKIE,
token,
options ?? {
expires: SWELL_COOKIE_EXPIRE,
}
)
}
}