mirror of
https://github.com/bitwarden/browser
synced 2026-02-07 12:13:45 +00:00
PM-23733 - Add preventProdAccessGuard logic
This commit is contained in:
@@ -0,0 +1 @@
|
||||
// TODO: add tests for this guard
|
||||
26
libs/angular/src/platform/guard/prevent-prod-access.guard.ts
Normal file
26
libs/angular/src/platform/guard/prevent-prod-access.guard.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { inject } from "@angular/core";
|
||||
import { CanMatchFn } from "@angular/router";
|
||||
import { firstValueFrom } from "rxjs";
|
||||
|
||||
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
|
||||
import { PRODUCTION_REGIONS } from "@bitwarden/common/platform/services/default-environment.service";
|
||||
|
||||
/**
|
||||
* Guard to prevent matching routes in production environments.
|
||||
* Allows for developer tooling that should only be accessible in non-production environments.
|
||||
*/
|
||||
export const preventProdAccessGuard: CanMatchFn = async (): Promise<boolean> => {
|
||||
const environmentService = inject(EnvironmentService);
|
||||
|
||||
const environment = await firstValueFrom(environmentService.environment$);
|
||||
|
||||
const region = environment.getRegion();
|
||||
|
||||
const prodRegions = PRODUCTION_REGIONS.map((regionConfig) => regionConfig.key);
|
||||
|
||||
if (prodRegions.includes(region)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
Reference in New Issue
Block a user