mirror of
https://github.com/bitwarden/browser
synced 2025-12-12 06:13:38 +00:00
Add device verification flow that requires users to enter an OTP when logging in from an unrecognized device. This includes: - New device verification route and guard - Email OTP verification component - Authentication timeout handling PM-8221
29 lines
972 B
TypeScript
29 lines
972 B
TypeScript
import { inject } from "@angular/core";
|
|
import { CanActivateFn, Router } from "@angular/router";
|
|
import { firstValueFrom } from "rxjs";
|
|
|
|
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;
|
|
};
|
|
}
|