2022-04-26 22:45:40 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2022-04-27 22:03:51 +03:00
|
|
|
export function logOut() {
|
|
|
|
setAuthToken(null);
|
|
|
|
gateway.close();
|
|
|
|
gateway.dispatch(GatewayEventType.BadAuth, -1);
|
|
|
|
}
|
|
|
|
|
2022-04-26 22:45:40 +03:00
|
|
|
useAuthHandlers();
|