import { observable, action } from "mobx";
import history from "@/router/history";

class AppStore {
    @observable userId = sessionStorage.getItem("userId");
    @observable token = sessionStorage.getItem("token");

    @action
    login(userId, token) {
        sessionStorage.setItem("userId", (this.userId = userId));
        sessionStorage.setItem("token", (this.token = token));
    }

    @action
    logout() {
        let path = "/login";
        sessionStorage.removeItem("userId");
        this.userId = undefined;
        sessionStorage.removeItem("token");
        this.token = undefined;

        history.push(path);
    }
}
export default new AppStore();
