import { decryptJWT } from "../helper";

/** 刷新token*/
class RefreshAccessToken {
    /** 存储键 */
    static _storageKey = 'x-access-token';

    /**
     * 保存
     * @param {String} token
     */
    public static set(token: string) {
        const stoken = { token, value: decryptJWT(token) };
        sessionStorage.setItem(this._storageKey, JSON.stringify(stoken));
    }
    /**
     * 获取
     */
    public static get() {
        const res = sessionStorage.getItem(this._storageKey);
        if (res) {
            return JSON.parse(res);
        }
        return undefined;
    }
    /**
     * 移出
     */
    public static clear() {
        return sessionStorage.removeItem(this._storageKey);
    }
}

export default RefreshAccessToken;