mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-05 18:26:40 +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({
|
const querySchema = z.object({
|
||||||
resourceId: z.coerce.number().int().positive().optional(),
|
resourceId: z.coerce.number().int().positive().optional(),
|
||||||
idpId: 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)
|
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) {
|
if (resourceId) {
|
||||||
const [resource] = await db
|
const [resource] = await db
|
||||||
.select()
|
.select()
|
||||||
@@ -118,7 +117,7 @@ export async function loadLoginPage(
|
|||||||
|
|
||||||
orgId = idpOrgLink.orgId;
|
orgId = idpOrgLink.orgId;
|
||||||
} else if (parsedQuery.data.orgId) {
|
} else if (parsedQuery.data.orgId) {
|
||||||
orgId = parsedQuery.data.orgId.toString();
|
orgId = parsedQuery.data.orgId;
|
||||||
}
|
}
|
||||||
|
|
||||||
const loginPage = await query(orgId, fullDomain);
|
const loginPage = await query(orgId, fullDomain);
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import { AxiosResponse } from "axios";
|
|||||||
import { ListIdpsResponse } from "@server/routers/idp";
|
import { ListIdpsResponse } from "@server/routers/idp";
|
||||||
import { getTranslations } from "next-intl/server";
|
import { getTranslations } from "next-intl/server";
|
||||||
import { build } from "@server/build";
|
import { build } from "@server/build";
|
||||||
|
import { LoadLoginPageResponse } from "@server/routers/loginPage/types";
|
||||||
|
|
||||||
export const dynamic = "force-dynamic";
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
@@ -33,6 +34,33 @@ export default async function Page(props: {
|
|||||||
redirect("/");
|
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;
|
let redirectUrl: string | undefined = undefined;
|
||||||
if (searchParams.redirect) {
|
if (searchParams.redirect) {
|
||||||
redirectUrl = cleanRedirect(searchParams.redirect as string);
|
redirectUrl = cleanRedirect(searchParams.redirect as string);
|
||||||
|
|||||||
@@ -91,10 +91,10 @@ export default function OrgPolicyResult({
|
|||||||
? async () => {
|
? async () => {
|
||||||
try {
|
try {
|
||||||
await api.post("/auth/logout", undefined);
|
await api.post("/auth/logout", undefined);
|
||||||
router.push("/auth/login");
|
router.push(`/auth/login?orgId=${orgId}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error during logout:", error);
|
console.error("Error during logout:", error);
|
||||||
router.push("/auth/login");
|
router.push(`/auth/login?orgId=${orgId}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
|
|||||||
Reference in New Issue
Block a user