const LocalStore = require('./Stores/Local');
const CookieStore = require('./Stores/Cookie');
const JWTDecode = require('jwt-decode');

class JWTManager {
    /**
     * Construct the class
     */
    constructor() {
        this.config = {
            store: 'cookie',
            expiryCheck: 60
        };
    }

    /**
     * Set the token
     *
     * @param token
     * @returns {string}
     */
    setToken(token) {
        let Store = this.getStore();

        Store.set(token);

        return token;
    }

    /**
     * Get the JWT Token
     *
     * @returns {string|null}
     */
    getToken() {
        let Store = this.getStore();
        
        return Store.get();
    }

    /**
     * Forget the current token
     */
    forget() {
        let Store = this.getStore();

        Store.forget();
    }

    /**
     * Forget the old token and set the new token
     *
     * @param token
     */
    refresh(token)
    {
        let Store = this.getStore();
        Store.forget();
        Store.set(token);
    }

    /**
     * Get the store
     */
    getStore() {
        if (this.config.store === 'local') {
            return LocalStore;
        } else if (this.config.store === 'cookie') {
            return CookieStore;
        }
    }
}

export default JWTManager;
@@ -280,23 +280,26 @@
     
-expiryCheck: 60
+secondsInterval: 3
 %0A   
@@ -1001,24 +1001,24 @@
 e.forget();%0A
-
         Stor
@@ -1030,32 +1030,789 @@
 (token);%0A    %7D%0A%0A
+    /**%0A     * Decode the current token%0A     *%0A     * @return %7Bobject%7D%0A     */%0A    decode()%0A    %7B%0A        let token = this.getToken();%0A%0A        if (token) %7B%0A            return JWTDecode(token);%0A        %7D%0A    %7D%0A%0A    /**%0A     * Run the callback automatically when the token is%0A     * due to expire within the given remainingSeconds%0A     *%0A     * @param %7Bint%7D remainingSeconds%0A     * @param %7Bcallable%7D callback%0A     */%0A    monitor(remainingSeconds = 60, callback)%0A    %7B%0A        setInterval(() =%3E %7B%0A            let decoded = this.decode();%0A            let secondsUntilExpiry = decoded.exp - (Date.now() / 1000);%0A%0A            if (secondsUntilExpiry %3C= remainingSeconds) %7B%0A                callback();%0A            %7D%0A        %7D, this.config.secondsInterval);%0A    %7D%0A%0A
     /**%0A     * G

Add monitor and decode methods