replace mgmt service request

This commit is contained in:
peintnermax
2024-08-27 11:27:43 +02:00
parent 50c360c0cf
commit 2a1cb2d38b
3 changed files with 10 additions and 7 deletions

View File

@@ -2,7 +2,7 @@ import { idpTypeToSlug } from "@/lib/idp";
import {
getActiveIdentityProviders,
getLoginSettings,
getOrgsByDomainSuffix,
getOrgsByDomain,
listAuthenticationMethodTypes,
listUsers,
startIdentityProviderFlow,
@@ -112,13 +112,14 @@ export async function POST(request: NextRequest) {
if (
!orgToRegisterOn &&
loginName &&
ORG_SUFFIX_REGEX.test(loginName)
ORG_SUFFIX_REGEX.test(loginName) &&
loginSettings.allowDomainDiscovery
) {
const matched = ORG_SUFFIX_REGEX.exec(loginName);
const suffix = matched?.[1] ?? "";
// this just returns orgs where the suffix is set as primary domain
const orgs = await getOrgsByDomainSuffix(suffix);
const orgs = await getOrgsByDomain(suffix);
orgToRegisterOn =
orgs.result && orgs.result.length === 1
? orgs.result[0].id

View File

@@ -6,7 +6,7 @@ import {
createCallback,
getActiveIdentityProviders,
getAuthRequest,
getOrgByDomain,
getOrgsByDomain,
listSessions,
startIdentityProviderFlow,
} from "@/lib/zitadel";
@@ -147,8 +147,10 @@ export async function GET(request: NextRequest) {
const matched = ORG_DOMAIN_SCOPE_REGEX.exec(orgDomainScope);
const orgDomain = matched?.[1] ?? "";
if (orgDomain) {
const org = await getOrgByDomain(orgDomain);
organization = org?.org?.id ?? "";
const orgs = await getOrgsByDomain(orgDomain);
if (orgs.result && orgs.result.length === 1) {
organization = orgs.result[0].id ?? "";
}
}
}
}

View File

@@ -293,7 +293,7 @@ export async function listUsers({
);
}
export async function getOrgsByDomainSuffix(domain: string) {
export async function getOrgsByDomain(domain: string) {
return orgService.listOrganizations(
{
queries: [