parse orgId from authrequest scope

This commit is contained in:
peintnermax
2024-03-11 14:32:54 +01:00
parent 2ef1af862b
commit 49b86d2df1
2 changed files with 15 additions and 1 deletions

View File

@@ -16,6 +16,8 @@ async function loadSessions(ids: string[]): Promise<Session[]> {
return response?.sessions ?? []; return response?.sessions ?? [];
} }
const ORG_SCOPE_REGEX = /urn:zitadel:iam:org:id:([0-9]*)/g;
function findSession( function findSession(
sessions: Session[], sessions: Session[],
authRequest: AuthRequest authRequest: AuthRequest
@@ -87,6 +89,18 @@ export async function GET(request: NextRequest) {
registerUrl.searchParams.set("authRequestId", authRequest?.id); registerUrl.searchParams.set("authRequestId", authRequest?.id);
} }
if (
authRequest.scope &&
authRequest.scope.find((s) => ORG_SCOPE_REGEX.test(s))
) {
const orgId = authRequest.scope
.find((s) => ORG_SCOPE_REGEX.test(s))
?.match(ORG_SCOPE_REGEX)?.[1];
console.log(orgId);
if (orgId) {
registerUrl.searchParams.set("orgId", orgId);
}
}
return NextResponse.redirect(registerUrl); return NextResponse.redirect(registerUrl);
} }

View File

@@ -3,7 +3,7 @@ import React from "react";
import { getBrandingSettings, server } from "#/lib/zitadel"; import { getBrandingSettings, server } from "#/lib/zitadel";
import { Logo } from "#/ui/Logo"; import { Logo } from "#/ui/Logo";
export default async function Layout({ export default async function Template({
children, children,
}: { }: {
children: React.ReactNode; children: React.ReactNode;