mirror of
https://github.com/fosrl/pangolin.git
synced 2026-01-28 22:00:51 +00:00
redirect to org login via query param
This commit is contained in:
@@ -25,7 +25,7 @@ import { LoadLoginPageResponse } from "@server/routers/loginPage/types";
|
||||
const querySchema = z.object({
|
||||
resourceId: z.coerce.number().int().positive().optional(),
|
||||
idpId: z.coerce.number().int().positive().optional(),
|
||||
orgId: z.coerce.number().int().positive().optional(),
|
||||
orgId: z.string().min(1).optional(),
|
||||
fullDomain: z.string().min(1)
|
||||
});
|
||||
|
||||
@@ -87,9 +87,8 @@ export async function loadLoginPage(
|
||||
);
|
||||
}
|
||||
|
||||
const { resourceId, idpId, fullDomain } = parsedQuery.data;
|
||||
let { resourceId, idpId, fullDomain, orgId } = parsedQuery.data;
|
||||
|
||||
let orgId;
|
||||
if (resourceId) {
|
||||
const [resource] = await db
|
||||
.select()
|
||||
@@ -118,7 +117,7 @@ export async function loadLoginPage(
|
||||
|
||||
orgId = idpOrgLink.orgId;
|
||||
} else if (parsedQuery.data.orgId) {
|
||||
orgId = parsedQuery.data.orgId.toString();
|
||||
orgId = parsedQuery.data.orgId;
|
||||
}
|
||||
|
||||
const loginPage = await query(orgId, fullDomain);
|
||||
|
||||
@@ -13,6 +13,7 @@ import { AxiosResponse } from "axios";
|
||||
import { ListIdpsResponse } from "@server/routers/idp";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { build } from "@server/build";
|
||||
import { LoadLoginPageResponse } from "@server/routers/loginPage/types";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
@@ -33,6 +34,33 @@ export default async function Page(props: {
|
||||
redirect("/");
|
||||
}
|
||||
|
||||
// Check for orgId and redirect to org-specific login page if found
|
||||
const orgId = searchParams.orgId as string | undefined;
|
||||
let loginPageDomain: string | undefined;
|
||||
if (orgId) {
|
||||
try {
|
||||
const res = await priv.get<AxiosResponse<LoadLoginPageResponse>>(
|
||||
`/login-page?orgId=${orgId}`
|
||||
);
|
||||
|
||||
if (res && res.status === 200 && res.data.data.fullDomain) {
|
||||
loginPageDomain = res.data.data.fullDomain;
|
||||
}
|
||||
} catch (e) {
|
||||
console.debug("No custom login page found for org", orgId);
|
||||
}
|
||||
}
|
||||
|
||||
if (loginPageDomain) {
|
||||
const redirectUrl = searchParams.redirect as string | undefined;
|
||||
|
||||
let url = `https://${loginPageDomain}/auth/org`;
|
||||
if (redirectUrl) {
|
||||
url += `?redirect=${redirectUrl}`;
|
||||
}
|
||||
redirect(url);
|
||||
}
|
||||
|
||||
let redirectUrl: string | undefined = undefined;
|
||||
if (searchParams.redirect) {
|
||||
redirectUrl = cleanRedirect(searchParams.redirect as string);
|
||||
|
||||
@@ -91,10 +91,10 @@ export default function OrgPolicyResult({
|
||||
? async () => {
|
||||
try {
|
||||
await api.post("/auth/logout", undefined);
|
||||
router.push("/auth/login");
|
||||
router.push(`/auth/login?orgId=${orgId}`);
|
||||
} catch (error) {
|
||||
console.error("Error during logout:", error);
|
||||
router.push("/auth/login");
|
||||
router.push(`/auth/login?orgId=${orgId}`);
|
||||
}
|
||||
}
|
||||
: undefined,
|
||||
|
||||
Reference in New Issue
Block a user