23 lines
577 B
JavaScript
23 lines
577 B
JavaScript
|
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);
|
||
|
}
|
||
|
|
||
|
useAuthHandlers();
|