fixed types

This commit is contained in:
Fran Jurmanović
2021-06-02 23:29:05 +02:00
parent c840041b51
commit 8754b4391b
26 changed files with 185 additions and 175 deletions

View File

@@ -1,35 +1,43 @@
import { AppMainElement } from "components/";
import { AppService } from "core/services";
import { AuthService } from "services/";
class AuthStore {
private _token;
private _userDetails;
private _token: string;
private _userDetails: UserDetails;
private authService: AuthService;
private domEvents: any = {
tokenchange: new Event("tokenchange"),
};
constructor(private appService: AppService) {
constructor(
private appMain: AppMainElement,
private appService: AppService
) {
this.token = localStorage.getItem("token");
this.authService = new AuthService(this.appService);
}
get token() {
get token(): string {
if (this._token == "null") return null;
if (this._token == "undefined") return undefined;
return this._token;
}
set token(token) {
this._token = token;
localStorage.setItem("token", token);
window.dispatchEvent(this.domEvents.tokenchange);
set token(token: string) {
const { _token } = this;
const _changed = token != _token;
if (_changed) {
this._token = token;
localStorage.setItem("token", token);
this.appMain.dispatchEvent(this.domEvents.tokenchange);
}
}
get user() {
get user(): UserDetails {
return this._userDetails;
}
set user(userDetails) {
set user(userDetails: UserDetails) {
this._userDetails = userDetails;
}
@@ -57,10 +65,18 @@ class AuthStore {
}
};
userLogout = () => {
userLogout = (): void => {
this.token = null;
localStorage.removeItem("token");
};
}
export default AuthStore;
export type UserDetails = {
id: string;
username: string;
email: string;
dateCreated: string;
dateUpdated: string;
};