fixed architecture to dispatch events when routes and token changes

This commit is contained in:
Fran Jurmanović
2021-05-31 12:00:07 +02:00
parent 48df6fc7cf
commit e1ab0e51d6
10 changed files with 131 additions and 29 deletions

View File

@@ -5,6 +5,9 @@ class AuthStore {
private _token;
private _userDetails;
private authService: AuthService;
private domEvents: any = {
tokenchange: new Event("tokenchange"),
};
constructor(private appService: AppService) {
this.token = localStorage.getItem("token");
this.authService = new AuthService(this.appService);
@@ -19,6 +22,7 @@ class AuthStore {
set token(token) {
this._token = token;
localStorage.setItem("token", token);
window.dispatchEvent(this.domEvents.tokenchange);
}
get user() {
@@ -52,6 +56,11 @@ class AuthStore {
throw err;
}
};
userLogout = () => {
this.token = null;
localStorage.removeItem("token");
};
}
export default AuthStore;