import { Token } from "../model/Token";
import store from "store";
import { NAMESPACE } from "../constants/config/storage.config";

/**
 * @description: 令牌存储服务
 * @author ChenRui
 * @date 2020/12/18 17:25
 */
class TokenStore {
  private static readonly TOKEN = NAMESPACE + "token";

  public set token(token: Token | undefined) {
    if (token) {
      store.set(TokenStore.TOKEN, token);
    } else {
      store.remove(TokenStore.TOKEN);
    }
  }

  public get token(): Token | undefined {
    return store.get(TokenStore.TOKEN);
  }
}
const tokenStore = new TokenStore();
export { tokenStore };
