argos/dmp-frontend/src/app/unauthorized/unauthorized.component.ts

33 lines
1.1 KiB
TypeScript
Raw Normal View History

2017-12-18 16:55:12 +01:00
import { AuthService } from '../services/auth/auth.service';
import { Component, Input } from "@angular/core";
import { ActivatedRoute, Router } from "@angular/router";
@Component({
selector: 'unauthorized-component',
templateUrl: './unauthorized.component.html'
})
export class UnauthorizedComponent {
@Input()
public message: string;
constructor(
private authService: AuthService,
private route: ActivatedRoute,
private router: Router
) { }
ngAfterViewInit() {
let returnUrl = this.route.snapshot.queryParams['returnUrl'] || '/';
let principal = this.authService.current();
if (!principal) {
this.router.navigate(['/login'], { queryParams: { returnUrl: returnUrl } });
}
else {
this.authService.me().subscribe(
principal => {
if (!principal) this.router.navigate(['/login'], { queryParams: { returnUrl: returnUrl } });
2018-01-31 16:39:16 +01:00
else this.router.navigate(["/"])
2017-12-18 16:55:12 +01:00
},
err => console.error('An error occurred', err));
}
}
}