mirror of
https://github.com/bitwarden/browser
synced 2025-12-10 21:33:27 +00:00
* refactor(two-factor-service) [PM-21204]: Stub API methods in TwoFactorService (domain). * refactor(two-factor-service) [PM-21204]: Build out stubs and add documentation. * refactor(two-factor-service) [PM-21204]: Update TwoFactorApiService call sites to use TwoFactorService. * refactor(two-fatcor) [PM-21204]: Remove deprecated and unused formPromise methods. * refactor(two-factor) [PM-21204]: Move 2FA-supporting services into common/auth/two-factor feature namespace. * refactor(two-factor) [PM-21204]: Update imports for service/init containers. * feat(two-factor) [PM-21204]: Add a disabling flow for Premium 2FA when enabled on a non-Premium account. * fix(two-factor-service) [PM-21204]: Fix type-safety of module constants. * fix(multiple) [PM-21204]: Prettier. * fix(user-verification-dialog) [PM-21204]: Remove bodyText configuration for this use. * fix(user-verification-dialog) [PM-21204]: Improve the error message displayed to the user.
34 lines
1001 B
TypeScript
34 lines
1001 B
TypeScript
import { inject } from "@angular/core";
|
|
import {
|
|
ActivatedRouteSnapshot,
|
|
CanActivateFn,
|
|
Router,
|
|
RouterStateSnapshot,
|
|
UrlTree,
|
|
} from "@angular/router";
|
|
import { firstValueFrom } from "rxjs";
|
|
|
|
import { TwoFactorService } from "@bitwarden/common/auth/two-factor";
|
|
|
|
import { LoginStrategyServiceAbstraction } from "../../common";
|
|
|
|
export const TwoFactorAuthGuard: CanActivateFn = async (
|
|
route: ActivatedRouteSnapshot,
|
|
routerState: RouterStateSnapshot,
|
|
): Promise<boolean | UrlTree> => {
|
|
const loginStrategyService = inject(LoginStrategyServiceAbstraction);
|
|
const twoFactorService = inject(TwoFactorService);
|
|
const router = inject(Router);
|
|
|
|
const currentAuthType = await firstValueFrom(loginStrategyService.currentAuthType$);
|
|
const userIsAuthenticating = currentAuthType !== null;
|
|
|
|
const twoFactorProviders = await twoFactorService.getProviders();
|
|
|
|
if (!userIsAuthenticating || twoFactorProviders == null) {
|
|
return router.createUrlTree(["/login"]);
|
|
}
|
|
|
|
return true;
|
|
};
|