mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-10-04 02:04:06 +00:00
38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
/**
|
|
* Shared environment helpers.
|
|
*/
|
|
import { readRuntimeConfigIsland } from "@/lib/runtime-config.shared";
|
|
import { readBoolEnv, readOptOutEnv } from "@/lib/runtime-env";
|
|
|
|
/**
|
|
* Whether the UI is running inside a Prowler Cloud deployment.
|
|
*
|
|
* Runtime read, resolved from two sources:
|
|
* - Browser: the runtime public-config island (`cloudEnabled`), rendered in
|
|
* <head> before any bundle runs, so calling this at module scope is safe.
|
|
* - Without a DOM (RSC, server actions, SSR, edge, Node) and jsdom tests
|
|
* without an island: `UI_CLOUD_ENABLED`. The island is produced from the
|
|
* same env var (lib/runtime-config.ts), so SSR and hydration always agree.
|
|
*/
|
|
export function isCloud(): boolean {
|
|
const islandConfig = readRuntimeConfigIsland();
|
|
if (islandConfig) return islandConfig.cloudEnabled;
|
|
|
|
return readBoolEnv("UI_CLOUD_ENABLED");
|
|
}
|
|
|
|
/**
|
|
* Whether visitors can create an account without an invitation.
|
|
*
|
|
* Prowler Cloud only: always on elsewhere. In Cloud it follows
|
|
* `UI_SELF_REGISTRATION_ENABLED` (island, then env), on unless "false".
|
|
*/
|
|
export function isSelfRegistrationEnabled(): boolean {
|
|
if (!isCloud()) return true;
|
|
|
|
const islandConfig = readRuntimeConfigIsland();
|
|
if (islandConfig) return islandConfig.selfRegistrationEnabled;
|
|
|
|
return readOptOutEnv("UI_SELF_REGISTRATION_ENABLED");
|
|
}
|