Fix routing on initial load

This commit is contained in:
William Brawner 2020-10-05 19:28:47 +00:00
parent 25dd6e5ccc
commit ff18e47036
4 changed files with 16 additions and 8 deletions

View file

@ -36,12 +36,13 @@ export class AppComponent {
if (this.cookieService.check('Authorization')) {
this.twigsService.getProfile().subscribe(user => {
this.user.next(user);
if (this.activatedRoute.pathFromRoot.length == 0) {
this.router.navigateByUrl("/budgets")
if (this.activatedRoute.snapshot.url.length == 0) {
this.router.navigateByUrl("/budgets");
}
});
} else {
this.router.navigateByUrl("/login")
} else if (this.activatedRoute.snapshot.url.length > 0) {
console.log(this.activatedRoute.snapshot.url)
this.router.navigateByUrl("/login");
}
updates.available.subscribe(
@ -91,6 +92,7 @@ export class AppComponent {
logout(): void {
this.twigsService.logout().subscribe(_ => {
this.location.go('/');
window.location.reload();
});
}

View file

@ -1,5 +1,4 @@
.dashboard {
color: #F1F1F1;
display: flex;
flex-wrap: wrap;
align-items: center;

View file

@ -16,19 +16,20 @@ export class BudgetsComponent implements OnInit {
constructor(
private app: AppComponent,
@Inject(TWIGS_SERVICE) private twigsService: TwigsService,
@Inject(TWIGS_SERVICE) private twigsService: TwigsService,
) { }
ngOnInit() {
this.app.setBackEnabled(false);
this.app.setTitle('Budgets')
this.app.user.subscribe(
user => {
if (!user) {
this.loading = false;
this.loggedIn = false;
this.app.setTitle('Welcome')
return;
}
this.app.setTitle('Budgets')
this.loggedIn = true;
this.loading = true;
this.twigsService.getBudgets().subscribe(

View file

@ -48,7 +48,13 @@ export class TwigsHttpService implements TwigsService {
}
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