1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-20 02:03:39 +00:00

move various angular bits into shared jslib

This commit is contained in:
Kyle Spearrin
2018-04-04 08:22:55 -04:00
parent 00bb0fdbdf
commit 579f970323
11 changed files with 366 additions and 16 deletions

View File

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