diff --git a/apps/login/src/components/register-form-without-password.tsx b/apps/login/src/components/register-form-without-password.tsx index 4b8d4d089ab..b81ef3eef0a 100644 --- a/apps/login/src/components/register-form-without-password.tsx +++ b/apps/login/src/components/register-form-without-password.tsx @@ -1,6 +1,6 @@ "use client"; -import { registerUser, RegisterUserResponse } from "@/lib/server/register"; +import { registerUser } from "@/lib/server/register"; import { LegalAndSupportSettings } from "@zitadel/proto/zitadel/settings/v2/legal_settings_pb"; import { useTranslations } from "next-intl"; import { useRouter } from "next/navigation"; @@ -66,6 +66,7 @@ export function RegisterFormWithoutPassword({ firstName: values.firstname, lastName: values.lastname, organization: organization, + authRequestId: authRequestId, }).catch((error) => { setError("Could not register user"); setLoading(false); @@ -98,22 +99,7 @@ export function RegisterFormWithoutPassword({ if (withPassword) { return router.push(`/register?` + new URLSearchParams(registerParams)); } else { - const session = (await submitAndRegister(value)) as RegisterUserResponse; - - const params = new URLSearchParams({}); - if (session?.factors?.user?.loginName) { - params.set("loginName", session.factors?.user?.loginName); - } - - if (organization) { - params.set("organization", organization); - } - - if (authRequestId) { - params.set("authRequestId", authRequestId); - } - - return router.push(`/passkey/set?` + new URLSearchParams(params)); + return submitAndRegister(value); } } diff --git a/apps/login/src/lib/server/register.ts b/apps/login/src/lib/server/register.ts index 35327adc7b5..2825bb97a6d 100644 --- a/apps/login/src/lib/server/register.ts +++ b/apps/login/src/lib/server/register.ts @@ -8,6 +8,7 @@ import { ChecksJson, ChecksSchema, } from "@zitadel/proto/zitadel/session/v2/session_service_pb"; +import { redirect } from "next/navigation"; type RegisterUserCommand = { email: string; @@ -23,7 +24,6 @@ export type RegisterUserResponse = { sessionId: string; factors: Factors | undefined; }; - export async function registerUser(command: RegisterUserCommand) { const human = await addHumanUser({ email: command.email, @@ -50,7 +50,7 @@ export async function registerUser(command: RegisterUserCommand) { const checks = create(ChecksSchema, checkPayload); - return createSessionAndUpdateCookie( + const session = await createSessionAndUpdateCookie( checks, undefined, command.authRequestId, @@ -61,4 +61,19 @@ export async function registerUser(command: RegisterUserCommand) { factors: session.factors, }; }); + + if (!session || !session.factors?.user) { + return { error: "Could not create session" }; + } + + const params = new URLSearchParams({ + loginName: session.factors.user.loginName, + organization: session.factors.user.organizationId, + }); + + if (command.authRequestId) { + params.append("authRequestId", command.authRequestId); + } + + return redirect("/passkey/set?" + params); }