1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-10-10 06:08:34 +02:00
bitwarden-browser/src/app/services/unauth-guard.service.ts

30 lines
831 B
TypeScript
Raw Normal View History

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;
}
}