mirror of
https://github.com/FJurmanovic/wallet-web.git
synced 2026-02-06 06:08:10 +00:00
fixed architecture to dispatch events when routes and token changes
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user