Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- canActivate(
- next: ActivatedRouteSnapshot,
- state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean {
- let accesstoken: string = next.queryParams.accesstoken;
- if (this.authService.IsAuthenticated) {
- let user = this.authService.GetUser();
- let CurrentDate = new Date();
- let date = CurrentDate.getFullYear() + "-" + (CurrentDate.getMonth() + 1) + "-" + CurrentDate.getDate();
- if (Date.parse(date) <= Date.parse(user.expire_date)) {
- return true;
- }
- }
- else if (!NOU(accesstoken)) { // In case current registered token is not valid, CheckAccess with new token
- // this.authService.logout();
- this.authService.checkAccess(accesstoken).subscribe(
- data => {
- if (data === true) {
- return true;
- } else {
- this.router.navigate(['/login']);
- return false;
- }
- },
- error => {
- }
- );
- }
- else {
- this.router.navigate(['/login']);
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement