import Cookies from 'js-cookie'

const TokenKey = 'AnQuanShengChan_token'

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

  if (Cookies.get(TokenKey)) {
    return Cookies.get(TokenKey)
  } else {
    return sessionStorage.getItem(TokenKey);
  }
}

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

export function removeToken() {
  sessionStorage.clear();
  return Cookies.remove(TokenKey)

}

export function setUser(user) {
  sessionStorage.setItem('anquanshengc_user', user);
  return Cookies.set('anquanshengc_user', user)
}

export function getUser() {
  //return Cookies.get(TokenKey)

  if (Cookies.get('anquanshengc_user')) {
    return Cookies.get('anquanshengc_user')
  } else {
    // return sessionStorage.getItem('anquanshengc_user');
    return sessionStorage.getItem('userInfo');
    
  }
}
