Skip to content

Commit 6973249

Browse files
committed
fix(config): expose the registration mode through getRegistrationMode
1 parent 3076c30 commit 6973249

4 files changed

Lines changed: 17 additions & 9 deletions

File tree

‎apps/sim/lib/core/config/deployment-projection.dom.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ vi.unmock('@/lib/core/config/env')
3939
vi.unmock('@/lib/core/config/env-flags')
4040

4141
import {
42+
getRegistrationMode,
4243
isAccessControlEnabled,
4344
isAuditLogsEnabled,
4445
isEmailPasswordAuthEnabled,
@@ -49,7 +50,6 @@ import {
4950
isSelfServeRegistrationClosed,
5051
isSessionPoliciesEnabled,
5152
isSsoEnabled,
52-
registrationMode,
5353
} from '@/lib/core/config/env-flags'
5454

5555
describe('browser enterprise flags', () => {
@@ -69,7 +69,7 @@ describe('browser enterprise flags', () => {
6969

7070
describe('browser registration flags', () => {
7171
it('take the projected registration mode over the browser environment', () => {
72-
expect(registrationMode).toBe('closed-no-email')
72+
expect(getRegistrationMode()).toBe('closed-no-email')
7373
expect(isSelfServeRegistrationClosed).toBe(true)
7474
expect(isEmailSignupAllowed).toBe(false)
7575
expect(isEmailPasswordAuthEnabled).toBe(false)

‎apps/sim/lib/core/config/deployment-shape.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
} from '@/lib/api/contracts/workspaces'
99
import { readDeploymentProjection } from '@/lib/core/config/deployment-projection'
1010
import {
11+
getRegistrationMode,
1112
isAccessControlEnabled,
1213
isAuditLogsEnabled,
1314
isAzureConfigured,
@@ -27,7 +28,6 @@ import {
2728
isSessionPoliciesEnabled,
2829
isSsoEnabled,
2930
isUsageMonitoringEnabled,
30-
registrationMode,
3131
} from '@/lib/core/config/env-flags'
3232

3333
/**
@@ -107,7 +107,7 @@ export function resolveDeploymentShape(): DeploymentShape {
107107
chatEnabled: isChatEnabled,
108108
azureConfigured: isAzureConfigured,
109109
cohereConfigured: isCohereConfigured,
110-
registrationMode,
110+
registrationMode: getRegistrationMode(),
111111
features: {
112112
accessControl: isAccessControlEnabled,
113113
auditLogs: isAuditLogsEnabled,

‎apps/sim/lib/core/config/env-flags.ts‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,11 @@ if (env.EGRESS_ALLOWED_HOSTS || env.EGRESS_ALLOWED_IP_RANGES) {
215215
})
216216
}
217217

218+
const resolvedRegistrationMode: RegistrationMode =
219+
typeof window === 'undefined'
220+
? resolveServerRegistrationMode()
221+
: (readProjectedRegistrationMode() ?? 'open')
222+
218223
/**
219224
* Who may create an account and whether email/password and email OTP work at all
220225
* (`REGISTRATION_MODE`; see `@sim/deployment-config/registration` for the modes).
@@ -225,10 +230,9 @@ if (env.EGRESS_ALLOWED_HOSTS || env.EGRESS_ALLOWED_IP_RANGES) {
225230
* without one (a bare 404 or `global-error` shell) reads `open`, which only affects
226231
* which links render — the server still refuses.
227232
*/
228-
export const registrationMode: RegistrationMode =
229-
typeof window === 'undefined'
230-
? resolveServerRegistrationMode()
231-
: (readProjectedRegistrationMode() ?? 'open')
233+
export function getRegistrationMode(): RegistrationMode {
234+
return resolvedRegistrationMode
235+
}
232236

233237
function resolveServerRegistrationMode(): RegistrationMode {
234238
const { mode, warnings } = resolveRegistrationMode(getEnv)
@@ -249,7 +253,7 @@ function resolveServerRegistrationMode(): RegistrationMode {
249253
return mode
250254
}
251255

252-
const registrationPolicy = getRegistrationPolicy(registrationMode)
256+
const registrationPolicy = getRegistrationPolicy(resolvedRegistrationMode)
253257

254258
/**
255259
* No self-serve account creation by any method, social included (`closed`,

‎packages/testing/src/mocks/env-flags.mock.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ export const envFlagsMockFns = {
144144
getBlacklistedProvidersFromEnv: vi.fn<() => string[]>(() => []),
145145
getAllowedMcpDomainsFromEnv: vi.fn<() => string[] | null>(() => null),
146146
getCostMultiplier: vi.fn<() => number>(() => 1),
147+
getRegistrationMode: vi.fn<() => RegistrationMode>(() => envFlagsState.registrationMode),
147148
}
148149

149150
/**
@@ -173,6 +174,9 @@ export function resetEnvFlagsMock(): void {
173174
envFlagsMockFns.getBlacklistedProvidersFromEnv.mockReset().mockImplementation(() => [])
174175
envFlagsMockFns.getAllowedMcpDomainsFromEnv.mockReset().mockImplementation(() => null)
175176
envFlagsMockFns.getCostMultiplier.mockReset().mockImplementation(() => 1)
177+
envFlagsMockFns.getRegistrationMode
178+
.mockReset()
179+
.mockImplementation(() => envFlagsState.registrationMode)
176180
envFlagsMockFns.getEgressAllowedHosts
177181
.mockReset()
178182
.mockImplementation(() =>

0 commit comments

Comments
 (0)