mirror of
https://github.com/bitwarden/jslib
synced 2025-12-10 05:13:41 +00:00
37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
import { Injectable } from '@angular/core';
|
|
import {
|
|
ActivatedRouteSnapshot,
|
|
CanActivate,
|
|
Router,
|
|
RouterStateSnapshot,
|
|
} from '@angular/router';
|
|
|
|
import { MessagingService } from 'jslib-common/abstractions/messaging.service';
|
|
import { UserService } from 'jslib-common/abstractions/user.service';
|
|
import { VaultTimeoutService } from 'jslib-common/abstractions/vaultTimeout.service';
|
|
|
|
@Injectable()
|
|
export class AuthGuardService implements CanActivate {
|
|
constructor(private vaultTimeoutService: VaultTimeoutService, private userService: UserService,
|
|
private router: Router, private messagingService: MessagingService) { }
|
|
|
|
async canActivate(route: ActivatedRouteSnapshot, routerState: RouterStateSnapshot) {
|
|
const isAuthed = await this.userService.isAuthenticated();
|
|
if (!isAuthed) {
|
|
this.messagingService.send('authBlocked');
|
|
return false;
|
|
}
|
|
|
|
const locked = await this.vaultTimeoutService.isLocked();
|
|
if (locked) {
|
|
if (routerState != null) {
|
|
this.messagingService.send('lockedUrl', { url: routerState.url });
|
|
}
|
|
this.router.navigate(['lock'], { queryParams: { promptBiometric: true }});
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|