import Cookies from 'js-cookie'

const TokenKey = 'store-token'
const LegacyTokenKey = 'Admin-TokenS'

const cookieOptions = {
  expires: 1,
  sameSite: 'Strict'
}
if (process.env.NODE_ENV === 'production') {
  cookieOptions.secure = true
}

export function getToken() {
  return Cookies.get(TokenKey) || Cookies.get(LegacyTokenKey)
}

export function setToken(token) {
  return Cookies.set(TokenKey, token, cookieOptions)
}

export function removeToken() {
  Cookies.remove(TokenKey)
  Cookies.remove(LegacyTokenKey)
}
