mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-17 02:16:38 +00:00
Update rekey endpoints and pages
This commit is contained in:
@@ -104,43 +104,13 @@ export async function getOlmToken(
|
||||
const resToken = generateSessionToken();
|
||||
await createOlmSession(resToken, existingOlm.olmId);
|
||||
|
||||
let orgIdToUse = orgId;
|
||||
let clientIdToUse;
|
||||
if (!orgIdToUse) {
|
||||
if (!existingOlm.clientId) {
|
||||
return next(
|
||||
createHttpError(
|
||||
HttpCode.BAD_REQUEST,
|
||||
"Olm is not associated with a client, orgId is required"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
const [client] = await db
|
||||
.select()
|
||||
.from(clients)
|
||||
.where(eq(clients.clientId, existingOlm.clientId))
|
||||
.limit(1);
|
||||
|
||||
if (!client) {
|
||||
return next(
|
||||
createHttpError(
|
||||
HttpCode.BAD_REQUEST,
|
||||
"Olm's associated client not found, orgId is required"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
orgIdToUse = client.orgId;
|
||||
clientIdToUse = client.clientId;
|
||||
} else {
|
||||
if (orgId) {
|
||||
// we did provide the org
|
||||
const [client] = await db
|
||||
.select()
|
||||
.from(clients)
|
||||
.where(
|
||||
and(eq(clients.orgId, orgIdToUse), eq(clients.olmId, olmId))
|
||||
) // we want to lock on to the client with this olmId otherwise it can get assigned to a random one
|
||||
.where(and(eq(clients.orgId, orgId), eq(clients.olmId, olmId))) // we want to lock on to the client with this olmId otherwise it can get assigned to a random one
|
||||
.limit(1);
|
||||
|
||||
if (!client) {
|
||||
@@ -167,6 +137,32 @@ export async function getOlmToken(
|
||||
.where(eq(olms.olmId, existingOlm.olmId));
|
||||
}
|
||||
|
||||
clientIdToUse = client.clientId;
|
||||
} else {
|
||||
if (!existingOlm.clientId) {
|
||||
return next(
|
||||
createHttpError(
|
||||
HttpCode.BAD_REQUEST,
|
||||
"Olm is not associated with a client, orgId is required"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
const [client] = await db
|
||||
.select()
|
||||
.from(clients)
|
||||
.where(eq(clients.clientId, existingOlm.clientId))
|
||||
.limit(1);
|
||||
|
||||
if (!client) {
|
||||
return next(
|
||||
createHttpError(
|
||||
HttpCode.BAD_REQUEST,
|
||||
"Olm's associated client not found, orgId is required"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
clientIdToUse = client.clientId;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user