mirror of
https://github.com/bitwarden/browser
synced 2025-12-19 09:43:23 +00:00
[PM-4348] Migrate AuthGuards to functions (#9595)
* Migrate auth guards * Fix remaining auth guard migration * Fix unauth guard usage * Add unit tests for auth guard and unauth guard * Remove unused angular DI code * Move auth related logic out fo sm guard * Add tests * Add more tests for unauth guard * Fix incorrect merge
This commit is contained in:
@@ -1,36 +1,10 @@
|
||||
import { Injectable, inject } from "@angular/core";
|
||||
import { CanActivate, CanActivateFn, Router, UrlTree } from "@angular/router";
|
||||
import { inject } from "@angular/core";
|
||||
import { CanActivateFn, Router, UrlTree } from "@angular/router";
|
||||
import { Observable, map } from "rxjs";
|
||||
|
||||
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
|
||||
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
|
||||
|
||||
/**
|
||||
* @deprecated use unauthGuardFn function instead
|
||||
*/
|
||||
@Injectable()
|
||||
export class UnauthGuard implements CanActivate {
|
||||
protected homepage = "vault";
|
||||
constructor(
|
||||
private authService: AuthService,
|
||||
private router: Router,
|
||||
) {}
|
||||
|
||||
async canActivate() {
|
||||
const authStatus = await this.authService.getAuthStatus();
|
||||
|
||||
if (authStatus === AuthenticationStatus.LoggedOut) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (authStatus === AuthenticationStatus.Locked) {
|
||||
return this.router.createUrlTree(["lock"]);
|
||||
}
|
||||
|
||||
return this.router.createUrlTree([this.homepage]);
|
||||
}
|
||||
}
|
||||
|
||||
type UnauthRoutes = {
|
||||
homepage: () => string;
|
||||
locked: string;
|
||||
|
||||
Reference in New Issue
Block a user