register with idp intent

This commit is contained in:
Max Peintner
2025-06-05 09:20:05 +02:00
parent 321007cee3
commit 07e5d548f0
2 changed files with 33 additions and 1 deletions

View File

@@ -24,6 +24,7 @@ import {
} from "@zitadel/proto/zitadel/user/v2/user_service_pb";
import { getLocale, getTranslations } from "next-intl/server";
import { headers } from "next/headers";
import { redirect } from "next/navigation";
const ORG_SUFFIX_REGEX = /(?<=@)(.+)/;
@@ -205,6 +206,7 @@ export default async function Page(props: {
}
}
// if addHumanUser is provided in the intent, expect that it can be created otherwise show an error
if (addHumanUser) {
let addHumanUserWithOrganization: AddHumanUserRequest;
if (orgToRegisterOn) {
@@ -241,6 +243,16 @@ export default async function Page(props: {
: "Could not create user",
);
}
} else {
// if no user was found, we will create a new user manually / redirect to the registration page
if (options.isCreationAllowed) {
const registerParams = new URLSearchParams({
idpIntentId: id,
idpIntentToken: token,
organization: organization ?? "",
});
return redirect(`/register?${registerParams})}`);
}
}
if (newUser) {

View File

@@ -7,6 +7,7 @@ import {
getLegalAndSupportSettings,
getLoginSettings,
getPasswordComplexitySettings,
retrieveIDPIntent,
} from "@/lib/zitadel";
import { Organization } from "@zitadel/proto/zitadel/org/v2/org_pb";
import { getLocale, getTranslations } from "next-intl/server";
@@ -19,7 +20,15 @@ export default async function Page(props: {
const locale = getLocale();
const t = await getTranslations({ locale, namespace: "register" });
let { firstname, lastname, email, organization, requestId } = searchParams;
let {
firstname,
lastname,
email,
organization,
requestId,
idpIntentId,
idpIntentToken,
} = searchParams;
const _headers = await headers();
const { serviceUrl } = getServiceUrlFromHeaders(_headers);
@@ -33,6 +42,17 @@ export default async function Page(props: {
}
}
let idpIntent;
if (idpIntentId && idpIntentToken) {
idpIntent = await retrieveIDPIntent({
serviceUrl,
id: idpIntentId,
token: idpIntentToken,
});
const { idpInformation, userId } = idpIntent;
}
const legal = await getLegalAndSupportSettings({
serviceUrl,
organization,