@@ -3,29 +3,16 @@ import { __unsafePrisma } from "@/prisma";
33import { OrgRole } from "@sourcebot/db" ;
44import { SINGLE_TENANT_ORG_ID } from "@/lib/constants" ;
55import { orgNotFound , ServiceError , userNotFound } from "@/lib/serviceError" ;
6- import { createLogger , getSeatCap } from "@sourcebot/shared" ;
6+ import { createLogger , getSeatCap , isMemberApprovalRequired } from "@sourcebot/shared" ;
77import { createAudit } from "@/ee/features/audit/audit" ;
88import { StatusCodes } from "http-status-codes" ;
99import { ErrorCode } from "./errorCodes" ;
1010import { syncWithLighthouse } from "@/features/billing/servicePing" ;
1111import { hasEntitlement } from "./entitlements" ;
12+ import { isScimEnabled } from "@/features/scim/utils" ;
1213
1314const 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-
2916export 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