Refactored initialization process to better facilitate auth if necessary

Date in user profile dialog now shows date
This commit is contained in:
Tzahi12345
2020-04-30 13:28:58 -04:00
parent 31f581c642
commit 81b0ef4a72
6 changed files with 25 additions and 16 deletions

View File

@@ -36,6 +36,8 @@ export class PostsService implements CanActivate {
reload_config = new BehaviorSubject<boolean>(false);
config_reloaded = new BehaviorSubject<boolean>(false);
service_initialized = new BehaviorSubject<boolean>(false);
initialized = false;
config = null;
constructor(private http: HttpClient, private router: Router, @Inject(DOCUMENT) private document: Document,
@@ -75,7 +77,7 @@ export class PostsService implements CanActivate {
this.jwtAuth();
}
} else {
this.config_reloaded.next(true);
this.setInitialized();
}
}
});
@@ -328,6 +330,9 @@ export class PostsService implements CanActivate {
}),
};
// needed to re-initialize parts of app after login
this.config_reloaded.next(true);
if (this.router.url === '/login') {
this.router.navigate(['/home']);
}
@@ -350,7 +355,7 @@ export class PostsService implements CanActivate {
call.subscribe(res => {
if (res['token']) {
this.afterLogin(res['user'], res['token']);
this.config_reloaded.next(true);
this.setInitialized();
}
}, err => {
if (err.status === 401) {
@@ -403,6 +408,12 @@ export class PostsService implements CanActivate {
this.openSnackBar('You must log in to access this page!');
}
setInitialized() {
this.service_initialized.next(true);
this.initialized = true;
this.config_reloaded.next(true);
}
public openSnackBar(message: string, action: string = '') {
this.snackBar.open(message, action, {
duration: 2000,