2018-06-10 04:02:45 +02:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
import {
|
|
|
|
CanActivate,
|
|
|
|
Router,
|
|
|
|
} from '@angular/router';
|
|
|
|
|
2019-02-14 03:55:11 +01:00
|
|
|
import { LockService } from 'jslib/abstractions/lock.service';
|
2018-06-10 04:02:45 +02:00
|
|
|
import { UserService } from 'jslib/abstractions/user.service';
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class UnauthGuardService implements CanActivate {
|
2019-02-14 03:55:11 +01:00
|
|
|
constructor(private lockService: LockService, private userService: UserService,
|
2018-06-10 04:02:45 +02:00
|
|
|
private router: Router) { }
|
|
|
|
|
|
|
|
async canActivate() {
|
|
|
|
const isAuthed = await this.userService.isAuthenticated();
|
|
|
|
if (isAuthed) {
|
2019-02-14 03:55:11 +01:00
|
|
|
const locked = await this.lockService.isLocked();
|
|
|
|
if (locked) {
|
2018-06-10 04:02:45 +02:00
|
|
|
this.router.navigate(['lock']);
|
|
|
|
} else {
|
|
|
|
this.router.navigate(['vault']);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|