11import type { User as AuthJsUser } from "next-auth" ;
22import { __unsafePrisma } from "@/prisma" ;
33import { OrgRole } from "@sourcebot/db" ;
4- import { SINGLE_TENANT_ORG_ID , SOURCEBOT_GUEST_USER_EMAIL , SOURCEBOT_GUEST_USER_ID , SOURCEBOT_SUPPORT_EMAIL } from "@/lib/constants" ;
5- import { hasEntitlement } from "@/lib/entitlements" ;
4+ import { SINGLE_TENANT_ORG_ID } from "@/lib/constants" ;
65import { isServiceError } from "@/lib/utils" ;
76import { orgNotFound , ServiceError , userNotFound } from "@/lib/serviceError" ;
87import { createLogger , getOfflineLicenseKey } from "@sourcebot/shared" ;
@@ -38,13 +37,7 @@ export const onCreateUser = async ({ user }: { user: AuthJsUser }) => {
3837 id : SINGLE_TENANT_ORG_ID ,
3938 } ,
4039 include : {
41- members : {
42- where : {
43- role : {
44- not : OrgRole . GUEST ,
45- }
46- }
47- } ,
40+ members : true ,
4841 }
4942 } ) ;
5043
@@ -67,8 +60,8 @@ export const onCreateUser = async ({ user }: { user: AuthJsUser }) => {
6760 throw new Error ( "Default org not found on single tenant user creation" ) ;
6861 }
6962
70- // First (non-guest) user to sign up bootstraps the org as its OWNER. This
71- // is how a fresh deployment gets its initial admin without manual setup.
63+ // First user to sign up bootstraps the org as its OWNER. This is how a
64+ // fresh deployment gets its initial admin without manual setup.
7265 const isFirstUser = defaultOrg . members . length === 0 ;
7366 if ( isFirstUser ) {
7467 await __unsafePrisma . $transaction ( async ( tx ) => {
@@ -134,68 +127,6 @@ export const onCreateUser = async ({ user }: { user: AuthJsUser }) => {
134127} ;
135128
136129
137- export const createGuestUser = async ( ) : Promise < ServiceError | boolean > => {
138- const hasAnonymousAccessEntitlement = await hasEntitlement ( "anonymous-access" ) ;
139- if ( ! hasAnonymousAccessEntitlement ) {
140- console . error ( `Anonymous access isn't supported in your current plan. For support, contact ${ SOURCEBOT_SUPPORT_EMAIL } .` ) ;
141- return {
142- statusCode : StatusCodes . FORBIDDEN ,
143- errorCode : ErrorCode . INSUFFICIENT_PERMISSIONS ,
144- message : "Public access is not supported in your current plan" ,
145- } satisfies ServiceError ;
146- }
147-
148- const org = await __unsafePrisma . org . findUnique ( {
149- where : { id : SINGLE_TENANT_ORG_ID } ,
150- } ) ;
151- if ( ! org ) {
152- return {
153- statusCode : StatusCodes . NOT_FOUND ,
154- errorCode : ErrorCode . NOT_FOUND ,
155- message : "Organization not found" ,
156- } satisfies ServiceError ;
157- }
158-
159- const user = await __unsafePrisma . user . upsert ( {
160- where : {
161- id : SOURCEBOT_GUEST_USER_ID ,
162- } ,
163- update : { } ,
164- create : {
165- id : SOURCEBOT_GUEST_USER_ID ,
166- name : "Guest" ,
167- email : SOURCEBOT_GUEST_USER_EMAIL ,
168- } ,
169- } ) ;
170-
171- await __unsafePrisma . org . update ( {
172- where : {
173- id : org . id ,
174- } ,
175- data : {
176- members : {
177- upsert : {
178- where : {
179- orgId_userId : {
180- orgId : org . id ,
181- userId : user . id ,
182- } ,
183- } ,
184- update : { } ,
185- create : {
186- role : OrgRole . GUEST ,
187- user : {
188- connect : { id : user . id } ,
189- } ,
190- } ,
191- } ,
192- } ,
193- } ,
194- } ) ;
195-
196- return true ;
197- } ;
198-
199130/**
200131 * Checks to see if the given organization has seat availability.
201132 * Seat availability is determined by the `seats` parameter in
@@ -207,13 +138,7 @@ export const orgHasAvailability = async (orgId: number): Promise<boolean> => {
207138 id : orgId ,
208139 } ,
209140 include : {
210- members : {
211- where : {
212- role : {
213- not : OrgRole . GUEST
214- }
215- }
216- } ,
141+ members : true ,
217142 }
218143 } ) ;
219144
0 commit comments