
export function getToken () {
  const token = window.localStorage.getItem('token') || undefined
  const createdAt = (window.localStorage.getItem('token-created-at') || '') - 0

  if (!createdAt) {
    const now = new Date()
    if (now.valueOf() - createdAt > (5 * 60 * 1000)) {
      return undefined
    }
  }

  return token
}

export function setToken (token) {
  const now = new Date()
  window.localStorage.setItem('token', token)
  window.localStorage.setItem('token-created-at', now.valueOf())
}

export function removeToken() {
  window.localStorage.removeItem('token')
  window.localStorage.removeItem('token-created-at')
}
