Skip to content

Commit 5648957

Browse files
nit
1 parent ed5bc42 commit 5648957

2 files changed

Lines changed: 16 additions & 16 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { __unsafePrisma } from "@/prisma";
2+
import { hasEntitlement } from "@/lib/entitlements";
3+
4+
export const isScimEnabled = async (orgId: number): Promise<boolean> => {
5+
if (!await hasEntitlement('scim')) {
6+
return false;
7+
}
8+
const tokenCount = await __unsafePrisma.scimToken.count({ where: { orgId } });
9+
return tokenCount > 0;
10+
};

packages/web/src/lib/authUtils.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,16 @@ import { __unsafePrisma } from "@/prisma";
33
import { OrgRole } from "@sourcebot/db";
44
import { SINGLE_TENANT_ORG_ID } from "@/lib/constants";
55
import { orgNotFound, ServiceError, userNotFound } from "@/lib/serviceError";
6-
import { createLogger, getSeatCap } from "@sourcebot/shared";
6+
import { createLogger, getSeatCap, isMemberApprovalRequired } from "@sourcebot/shared";
77
import { createAudit } from "@/ee/features/audit/audit";
88
import { StatusCodes } from "http-status-codes";
99
import { ErrorCode } from "./errorCodes";
1010
import { syncWithLighthouse } from "@/features/billing/servicePing";
1111
import { hasEntitlement } from "./entitlements";
12+
import { isScimEnabled } from "@/features/scim/utils";
1213

1314
const logger = createLogger('web-auth-utils');
1415

15-
/**
16-
* SCIM is "enabled" for an org once it has at least one SCIM token configured
17-
* (and the entitlement is present). When enabled, the IdP directory is the
18-
* source of truth for membership, so interactive-login JIT auto-join is
19-
* suppressed — users must be provisioned via SCIM.
20-
*/
21-
export const isScimEnabled = async (orgId: number): Promise<boolean> => {
22-
if (!await hasEntitlement('scim')) {
23-
return false;
24-
}
25-
const tokenCount = await __unsafePrisma.scimToken.count({ where: { orgId } });
26-
return tokenCount > 0;
27-
};
28-
2916
export const onCreateUser = async ({ user }: { user: AuthJsUser }) => {
3017
if (!user.id) {
3118
logger.error("User ID is undefined on user creation");
@@ -133,7 +120,10 @@ export const onCreateUser = async ({ user }: { user: AuthJsUser }) => {
133120
// When SCIM is enabled, auto-join is suppressed entirely: the IdP is the
134121
// source of truth, so a login for a user the IdP hasn't provisioned creates
135122
// the User row but no membership (they're denied until SCIM provisions them).
136-
else if (!defaultOrg.memberApprovalRequired && !(await isScimEnabled(SINGLE_TENANT_ORG_ID))) {
123+
else if (
124+
!isMemberApprovalRequired(defaultOrg) &&
125+
!(await isScimEnabled(defaultOrg.id))
126+
) {
137127
// Don't exceed the licensed seat count. The user row still exists;
138128
// they just aren't attached to the org until a seat frees up.
139129
const hasAvailability = await orgHasAvailability(defaultOrg.id);

0 commit comments

Comments
 (0)