mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-15 17:36:37 +00:00
redirect to org login via query param
This commit is contained in:
@@ -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