Add DoNotCreateNewClient

This commit is contained in:
Owen
2025-11-07 15:24:32 -08:00
parent 41e21acf42
commit c813202f92

View File

@@ -30,7 +30,8 @@ export const handleOlmRegisterMessage: MessageHandler = async (context) => {
return; return;
} }
const { publicKey, relay, olmVersion, orgId } = message.data; const { publicKey, relay, olmVersion, orgId, doNotCreateNewClient } =
message.data;
let client: Client; let client: Client;
if (orgId) { if (orgId) {
@@ -39,7 +40,8 @@ export const handleOlmRegisterMessage: MessageHandler = async (context) => {
orgId, orgId,
olm.userId, olm.userId,
olm.olmId, olm.olmId,
olm.name || "User Device" olm.name || "User Device",
doNotCreateNewClient ? true : false
); );
} catch (err) { } catch (err) {
logger.error( logger.error(
@@ -295,10 +297,9 @@ async function getOrCreateOrgClient(
userId: string | null, userId: string | null,
olmId: string, olmId: string,
name: string, name: string,
doNotCreateNewClient: boolean,
trx: Transaction | typeof db = db trx: Transaction | typeof db = db
): Promise<Client> { ): Promise<Client> {
let client: Client;
// get the org // get the org
const [org] = await trx const [org] = await trx
.select() .select()
@@ -327,7 +328,8 @@ async function getOrCreateOrgClient(
) // checking the olmid here because we want to create a new client PER OLM PER ORG ) // checking the olmid here because we want to create a new client PER OLM PER ORG
.limit(1); .limit(1);
if (!existingClient) { let client = existingClient;
if (!client && !doNotCreateNewClient) {
logger.debug( logger.debug(
`Client does not exist in org ${orgId}, creating new client for user ${userId}` `Client does not exist in org ${orgId}, creating new client for user ${userId}`
); );
@@ -388,7 +390,8 @@ async function getOrCreateOrgClient(
clientId: newClient.clientId clientId: newClient.clientId
}); });
await trx.insert(userClients).values({ // we also want to make sure that the user can see their own client if they are not an admin await trx.insert(userClients).values({
// we also want to make sure that the user can see their own client if they are not an admin
userId, userId,
clientId: newClient.clientId clientId: newClient.clientId
}); });
@@ -402,8 +405,6 @@ async function getOrCreateOrgClient(
} }
client = newClient; client = newClient;
} else {
client = existingClient;
} }
return client; return client;