1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-06 19:53:59 +00:00
Files
browser/libs/angular/src/auth/guards/active-auth.guard.ts
Addison Beck 56a3b14583 Introduce eslint errors for risky/circular imports (#14804)
* first draft at an idea dependency graph

* ignore existing errors

* remove conflicting rule regarding internal platform logic in libs

* review: allow components to import from platform
2025-05-23 08:01:25 -04:00

31 lines
1.1 KiB
TypeScript

import { inject } from "@angular/core";
import { CanActivateFn, Router } from "@angular/router";
import { firstValueFrom } from "rxjs";
// This import has been flagged as unallowed for this class. It may be involved in a circular dependency loop.
// eslint-disable-next-line no-restricted-imports
import { LoginStrategyServiceAbstraction } from "@bitwarden/auth/common";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
/**
* Guard that ensures there is an active login session before allowing access
* to the new device verification route.
* If not, redirects to login.
*/
export function activeAuthGuard(): CanActivateFn {
return async () => {
const loginStrategyService = inject(LoginStrategyServiceAbstraction);
const logService = inject(LogService);
const router = inject(Router);
// Check if we have a valid login session
const authType = await firstValueFrom(loginStrategyService.currentAuthType$);
if (authType === null) {
logService.error("No active login session found.");
return router.createUrlTree(["/login"]);
}
return true;
};
}