mirror of
https://github.com/FJurmanovic/wallet-web.git
synced 2026-11-11 15:51:10 +00:00
added authorization stores and fixed http client
This commit is contained in:
@@ -2,16 +2,24 @@ import { attr, targets, controller, target } from "@github/catalyst";
|
||||
import { closest, index, update, isTrue } from "core/utils";
|
||||
import { html, render, until } from "@github/jtml";
|
||||
import { PingService } from "services/";
|
||||
import { RouterService } from "core/services";
|
||||
import { AppService, HttpClient, RouterService } from "core/services";
|
||||
import { AuthStore } from "core/store";
|
||||
|
||||
@controller
|
||||
class AppMainElement extends HTMLElement {
|
||||
public routerService: RouterService;
|
||||
public authStore: AuthStore;
|
||||
private httpClient: HttpClient;
|
||||
public appService: AppService;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
connectedCallback() {
|
||||
this.httpClient = new HttpClient();
|
||||
this.appService = new AppService(this, this.httpClient);
|
||||
this.routerService = new RouterService(this);
|
||||
this.authStore = new AuthStore(this.appService);
|
||||
this.routerService.setRoutes([
|
||||
{
|
||||
path: "/",
|
||||
@@ -21,10 +29,30 @@ class AppMainElement extends HTMLElement {
|
||||
{
|
||||
path: "/home",
|
||||
component: "home-page",
|
||||
middleware: this.isAuth,
|
||||
},
|
||||
{
|
||||
path: "/rb",
|
||||
component: "register-page",
|
||||
},
|
||||
{
|
||||
path: "/unauthorized",
|
||||
component: "register-page",
|
||||
},
|
||||
{
|
||||
path: "token-expired",
|
||||
component: "register-page",
|
||||
},
|
||||
]);
|
||||
this.routerService.init();
|
||||
}
|
||||
|
||||
isAuth = () => {
|
||||
if (this.authStore?.token == null) {
|
||||
this.routerService.goTo("/unauthorized");
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export type { AppMainElement };
|
||||
|
||||
Reference in New Issue
Block a user