Newer
Older
securityFront / src / utils / auth.js
TAN YUE on 21 Dec 2020 1 KB 20201221 首页跳转功能
import Cookies from 'js-cookie'

const TokenKey = 'token'
const PublicKey = 'public_key'
const CurrentSystem = 'current_system'

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

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

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

export function getPublicKey() {
  return window.localStorage.getItem(PublicKey)
}

export function setPublicKey(publicKey) {
  return window.localStorage.setItem(PublicKey, publicKey)
}

export function removePublicKey() {
  return window.localStorage.removeItem(PublicKey)
}

export function getCurrentSys() {
  let currentSystem = window.localStorage.getItem(CurrentSystem)
  if (typeof (currentSystem) === 'undefined') {
    return undefined
  } else {
    currentSystem = JSON.parse(currentSystem)
    return currentSystem
  }
}

export function setCurrentSys(currentSystem) {
  console.log('in auth setCurrentSys')
  console.log(currentSystem)
  const currentSys = JSON.stringify(currentSystem)
  return window.localStorage.setItem(CurrentSystem, currentSys)
}

export function removeCurrentSys() {
  return window.localStorage.removeItem(CurrentSystem)
}