redirect from server

This commit is contained in:
Max Peintner
2024-10-28 16:02:58 +01:00
parent b8039be958
commit 357d462b16
2 changed files with 20 additions and 19 deletions

View File

@@ -1,6 +1,6 @@
"use client"; "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 { LegalAndSupportSettings } from "@zitadel/proto/zitadel/settings/v2/legal_settings_pb";
import { useTranslations } from "next-intl"; import { useTranslations } from "next-intl";
import { useRouter } from "next/navigation"; import { useRouter } from "next/navigation";
@@ -66,6 +66,7 @@ export function RegisterFormWithoutPassword({
firstName: values.firstname, firstName: values.firstname,
lastName: values.lastname, lastName: values.lastname,
organization: organization, organization: organization,
authRequestId: authRequestId,
}).catch((error) => { }).catch((error) => {
setError("Could not register user"); setError("Could not register user");
setLoading(false); setLoading(false);
@@ -98,22 +99,7 @@ export function RegisterFormWithoutPassword({
if (withPassword) { if (withPassword) {
return router.push(`/register?` + new URLSearchParams(registerParams)); return router.push(`/register?` + new URLSearchParams(registerParams));
} else { } else {
const session = (await submitAndRegister(value)) as RegisterUserResponse; return submitAndRegister(value);
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));
} }
} }

View File

@@ -8,6 +8,7 @@ import {
ChecksJson, ChecksJson,
ChecksSchema, ChecksSchema,
} from "@zitadel/proto/zitadel/session/v2/session_service_pb"; } from "@zitadel/proto/zitadel/session/v2/session_service_pb";
import { redirect } from "next/navigation";
type RegisterUserCommand = { type RegisterUserCommand = {
email: string; email: string;
@@ -23,7 +24,6 @@ export type RegisterUserResponse = {
sessionId: string; sessionId: string;
factors: Factors | undefined; factors: Factors | undefined;
}; };
export async function registerUser(command: RegisterUserCommand) { export async function registerUser(command: RegisterUserCommand) {
const human = await addHumanUser({ const human = await addHumanUser({
email: command.email, email: command.email,
@@ -50,7 +50,7 @@ export async function registerUser(command: RegisterUserCommand) {
const checks = create(ChecksSchema, checkPayload); const checks = create(ChecksSchema, checkPayload);
return createSessionAndUpdateCookie( const session = await createSessionAndUpdateCookie(
checks, checks,
undefined, undefined,
command.authRequestId, command.authRequestId,
@@ -61,4 +61,19 @@ export async function registerUser(command: RegisterUserCommand) {
factors: session.factors, 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);
} }