Fix routing on initial load
This commit is contained in:
parent
25dd6e5ccc
commit
ff18e47036
4 changed files with 16 additions and 8 deletions
|
@ -36,12 +36,13 @@ export class AppComponent {
|
||||||
if (this.cookieService.check('Authorization')) {
|
if (this.cookieService.check('Authorization')) {
|
||||||
this.twigsService.getProfile().subscribe(user => {
|
this.twigsService.getProfile().subscribe(user => {
|
||||||
this.user.next(user);
|
this.user.next(user);
|
||||||
if (this.activatedRoute.pathFromRoot.length == 0) {
|
if (this.activatedRoute.snapshot.url.length == 0) {
|
||||||
this.router.navigateByUrl("/budgets")
|
this.router.navigateByUrl("/budgets");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else if (this.activatedRoute.snapshot.url.length > 0) {
|
||||||
this.router.navigateByUrl("/login")
|
console.log(this.activatedRoute.snapshot.url)
|
||||||
|
this.router.navigateByUrl("/login");
|
||||||
}
|
}
|
||||||
|
|
||||||
updates.available.subscribe(
|
updates.available.subscribe(
|
||||||
|
@ -91,6 +92,7 @@ export class AppComponent {
|
||||||
logout(): void {
|
logout(): void {
|
||||||
this.twigsService.logout().subscribe(_ => {
|
this.twigsService.logout().subscribe(_ => {
|
||||||
this.location.go('/');
|
this.location.go('/');
|
||||||
|
window.location.reload();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
.dashboard {
|
.dashboard {
|
||||||
color: #F1F1F1;
|
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|
|
@ -21,14 +21,15 @@ export class BudgetsComponent implements OnInit {
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.app.setBackEnabled(false);
|
this.app.setBackEnabled(false);
|
||||||
this.app.setTitle('Budgets')
|
|
||||||
this.app.user.subscribe(
|
this.app.user.subscribe(
|
||||||
user => {
|
user => {
|
||||||
if (!user) {
|
if (!user) {
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
this.loggedIn = false;
|
this.loggedIn = false;
|
||||||
|
this.app.setTitle('Welcome')
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this.app.setTitle('Budgets')
|
||||||
this.loggedIn = true;
|
this.loggedIn = true;
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
this.twigsService.getBudgets().subscribe(
|
this.twigsService.getBudgets().subscribe(
|
||||||
|
|
|
@ -48,7 +48,13 @@ export class TwigsHttpService implements TwigsService {
|
||||||
}
|
}
|
||||||
|
|
||||||
logout(): Observable<void> {
|
logout(): Observable<void> {
|
||||||
return this.http.post<void>(this.apiUrl + '/login?logout', this.options);
|
return Observable.create(emitter => {
|
||||||
|
this.cookieService.delete('Authorization');
|
||||||
|
emitter.next();
|
||||||
|
emitter.complete();
|
||||||
|
})
|
||||||
|
// TODO: Implement this when JWT auth is implemented
|
||||||
|
// return this.http.post<void>(this.apiUrl + '/login?logout', this.options);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Budgets
|
// Budgets
|
||||||
|
|
Loading…
Reference in a new issue