This commit is contained in:
Owen
2025-10-04 18:36:44 -07:00
parent 3123f858bb
commit c2c907852d
320 changed files with 35785 additions and 2984 deletions

View File

@@ -1,8 +1,48 @@
import { db, loginPage, loginPageOrg } from "@server/db";
import config from "@server/lib/config";
import { eq } from "drizzle-orm";
export async function generateOidcRedirectUrl(
idpId: number,
orgId?: string,
loginPageId?: number
): Promise<string> {
let baseUrl: string | undefined;
const secure = config.getRawConfig().app.dashboard_url?.startsWith("https");
const method = secure ? "https" : "http";
if (loginPageId) {
const [res] = await db
.select()
.from(loginPage)
.where(eq(loginPage.loginPageId, loginPageId))
.limit(1);
if (res && res.fullDomain) {
baseUrl = `${method}://${res.fullDomain}`;
}
} else if (orgId) {
const [res] = await db
.select()
.from(loginPageOrg)
.where(eq(loginPageOrg.orgId, orgId))
.innerJoin(
loginPage,
eq(loginPage.loginPageId, loginPageOrg.loginPageId)
)
.limit(1);
if (res?.loginPage && res.loginPage.domainId && res.loginPage.fullDomain) {
baseUrl = `${method}://${res.loginPage.fullDomain}`;
}
}
if (!baseUrl) {
baseUrl = config.getRawConfig().app.dashboard_url!;
}
export function generateOidcRedirectUrl(idpId: number) {
const dashboardUrl = config.getRawConfig().app.dashboard_url;
const redirectPath = `/auth/idp/${idpId}/oidc/callback`;
const redirectUrl = new URL(redirectPath, dashboardUrl).toString();
const redirectUrl = new URL(redirectPath, baseUrl!).toString();
return redirectUrl;
}