44 lines
1.3 KiB
JavaScript
44 lines
1.3 KiB
JavaScript
(function () {
|
|
const RegistryApp = (window.RegistryApp = window.RegistryApp || {});
|
|
const { createSignal } = RegistryApp.runtime;
|
|
|
|
class RegistryStore {
|
|
constructor() {
|
|
[this.getView, this.setView] = createSignal("home");
|
|
[this.getIsAuthenticating, this.setIsAuthenticating] =
|
|
createSignal(false);
|
|
[this.getLoginError, this.setLoginError] = createSignal("");
|
|
}
|
|
|
|
startLogin() {
|
|
this.setLoginError("");
|
|
this.setIsAuthenticating(true);
|
|
}
|
|
|
|
failLogin(message) {
|
|
this.setIsAuthenticating(false);
|
|
this.setLoginError(message || "Authentication failed.");
|
|
}
|
|
|
|
completeLogin(payload) {
|
|
const OrgPortal = window.OrgPortal;
|
|
const portalData = payload?.portalData;
|
|
const session = payload?.session;
|
|
|
|
if (!OrgPortal || !portalData || !session) {
|
|
this.failLogin("Login response was missing portal data.");
|
|
return;
|
|
}
|
|
|
|
OrgPortal.data.applyLoginPayload(payload);
|
|
OrgPortal.store.hydrateFromPayload(payload);
|
|
|
|
this.setLoginError("");
|
|
this.setIsAuthenticating(false);
|
|
this.setView("portal");
|
|
}
|
|
}
|
|
|
|
RegistryApp.store = new RegistryStore();
|
|
})();
|