import Cookies from 'js-cookie'

const TokenKey = 'Web-Token'

/** Token Cookie 安全属性 */
function getTokenCookieOptions() {
  return {
    expires: 1,
    path: '/',
    sameSite: 'strict',
    secure: typeof location !== 'undefined' && location.protocol === 'https:'
  }
}

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

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

export function removeToken() {
  return Cookies.remove(TokenKey, getTokenCookieOptions())
}
