You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
argos/dmp-frontend/src/app/unauthorized/unauthorized.component.ts

36 lines
1.2 KiB
TypeScript

import { AfterViewInit, Component, Input } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { takeUntil } from 'rxjs/operators';
import { BaseComponent } from '../core/common/base/base.component';
import { AuthService } from '../services/auth/auth.service';
@Component({
selector: 'app-unauthorized-component',
templateUrl: './unauthorized.component.html'
})
export class UnauthorizedComponent extends BaseComponent implements AfterViewInit {
@Input()
public message: string;
constructor(
private authService: AuthService,
private route: ActivatedRoute,
private router: Router
) { super(); }
ngAfterViewInit() {
const returnUrl = this.route.snapshot.queryParams['returnUrl'] || '/';
const principal = this.authService.current();
if (!principal) {
this.router.navigate(['/login'], { queryParams: { returnUrl: returnUrl } });
} else {
this.authService.me()
.pipe(takeUntil(this._destroyed))
.subscribe(
result => {
if (!result) { this.router.navigate(['/login'], { queryParams: { returnUrl: returnUrl } }); } else { this.router.navigate(['/']); }
},
err => console.error('An error occurred', err));
}
}
}