2021-04-21 23:52:48 +02:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
import {
|
2021-06-08 23:35:03 +02:00
|
|
|
ActivatedRouteSnapshot,
|
2021-04-21 23:52:48 +02:00
|
|
|
CanActivate,
|
|
|
|
Router,
|
|
|
|
} from '@angular/router';
|
|
|
|
|
2021-06-03 18:58:57 +02:00
|
|
|
import { UserService } from 'jslib-common/abstractions/user.service';
|
|
|
|
import { VaultTimeoutService } from 'jslib-common/abstractions/vaultTimeout.service';
|
2021-04-21 23:52:48 +02:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class UnauthGuardService implements CanActivate {
|
2021-06-08 23:35:03 +02:00
|
|
|
|
|
|
|
protected homepage = 'vault';
|
2021-04-21 23:52:48 +02:00
|
|
|
constructor(private vaultTimeoutService: VaultTimeoutService, private userService: UserService,
|
|
|
|
private router: Router) { }
|
|
|
|
|
|
|
|
async canActivate() {
|
|
|
|
const isAuthed = await this.userService.isAuthenticated();
|
|
|
|
if (isAuthed) {
|
|
|
|
const locked = await this.vaultTimeoutService.isLocked();
|
|
|
|
if (locked) {
|
|
|
|
this.router.navigate(['lock']);
|
|
|
|
} else {
|
2021-06-08 23:35:03 +02:00
|
|
|
this.router.navigate([this.homepage]);
|
2021-04-21 23:52:48 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|