1
0
mirror of https://github.com/bitwarden/browser synced 2026-01-03 17:13:47 +00:00

auth guards

This commit is contained in:
Kyle Spearrin
2018-06-09 22:02:45 -04:00
parent 9f1c7a0a32
commit 7ebd18b00d
8 changed files with 67 additions and 19 deletions

View File

@@ -0,0 +1,29 @@
import { Injectable } from '@angular/core';
import {
CanActivate,
Router,
} from '@angular/router';
import { CryptoService } from 'jslib/abstractions/crypto.service';
import { UserService } from 'jslib/abstractions/user.service';
@Injectable()
export class UnauthGuardService implements CanActivate {
constructor(private cryptoService: CryptoService, private userService: UserService,
private router: Router) { }
async canActivate() {
const isAuthed = await this.userService.isAuthenticated();
if (isAuthed) {
const key = await this.cryptoService.getKey();
if (key == null) {
this.router.navigate(['lock']);
} else {
this.router.navigate(['vault']);
}
return false;
}
return true;
}
}