import gateway, { GatewayEventType } from "./gateway"; import { setAuthToken } from "./storage"; import { overlayStore } from "./stores"; function useAuthHandlers() { gateway.subscribe(GatewayEventType.Ready, () => { overlayStore.close("login"); overlayStore.close("createAccount"); }); gateway.subscribe(GatewayEventType.BadAuth, () => { overlayStore.open("login", {}); }); } export function authWithToken(token, shouldUpdate=false) { if (shouldUpdate) setAuthToken(token); gateway.init(token); } export function logOut() { setAuthToken(null); gateway.close(); gateway.dispatch(GatewayEventType.BadAuth, -1); } useAuthHandlers();