Skip to content

Commit

Permalink
Rename newDeviceVerificationGuard to activeAuthGuard
Browse files Browse the repository at this point in the history
  • Loading branch information
alec-livefront committed Jan 16, 2025
1 parent a87d2b6 commit 09a4441
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 8 deletions.
4 changes: 2 additions & 2 deletions apps/browser/src/popup/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { unauthUiRefreshSwap } from "@bitwarden/angular/auth/functions/unauth-ui
import {
authGuard,
lockGuard,
newDeviceVerificationGuard,
activeAuthGuard,
redirectGuard,
tdeDecryptionRequiredGuard,
unauthGuardFn,
Expand Down Expand Up @@ -238,7 +238,7 @@ const routes: Routes = [
{
path: "device-verification",
component: ExtensionAnonLayoutWrapperComponent,
canActivate: [newDeviceVerificationGuard()],
canActivate: [activeAuthGuard()],
children: [{ path: "", component: NewDeviceVerificationComponent }],
data: {
pageIcon: DeviceVerificationIcon,
Expand Down
4 changes: 2 additions & 2 deletions apps/desktop/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { unauthUiRefreshSwap } from "@bitwarden/angular/auth/functions/unauth-ui
import {
authGuard,
lockGuard,
newDeviceVerificationGuard,
activeAuthGuard,
redirectGuard,
tdeDecryptionRequiredGuard,
unauthGuardFn,
Expand Down Expand Up @@ -120,7 +120,7 @@ const routes: Routes = [
{
path: "device-verification",
component: AnonLayoutWrapperComponent,
canActivate: [newDeviceVerificationGuard()],
canActivate: [activeAuthGuard()],
children: [{ path: "", component: NewDeviceVerificationComponent }],
data: {
pageIcon: DeviceVerificationIcon,
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/app/oss-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
redirectGuard,
tdeDecryptionRequiredGuard,
unauthGuardFn,
newDeviceVerificationGuard,
activeAuthGuard,
} from "@bitwarden/angular/auth/guards";
import { canAccessFeature } from "@bitwarden/angular/platform/guard/feature-flag.guard";
import { generatorSwap } from "@bitwarden/angular/tools/generator/generator-swap";
Expand Down Expand Up @@ -591,7 +591,7 @@ const routes: Routes = [
},
{
path: "device-verification",
canActivate: [newDeviceVerificationGuard()],
canActivate: [activeAuthGuard()],
children: [
{
path: "",
Expand Down
28 changes: 28 additions & 0 deletions libs/angular/src/auth/guards/active-auth.guard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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;
};
}
2 changes: 1 addition & 1 deletion libs/angular/src/auth/guards/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from "./auth.guard";
export * from "./active-auth.guard";
export * from "./lock.guard";
export * from "./redirect.guard";
export * from "./tde-decryption-required.guard";
export * from "./unauth.guard";
export * from "./new-device-verification.guard";
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { LogService } from "@bitwarden/common/platform/abstractions/log.service"
* to the new device verification route.
* If not, redirects to login.
*/
export function newDeviceVerificationGuard(): CanActivateFn {
export function activeAuthGuard(): CanActivateFn {
return async () => {
const loginStrategyService = inject(LoginStrategyServiceAbstraction);
const logService = inject(LogService);
Expand Down

0 comments on commit 09a4441

Please sign in to comment.