mirror of
https://github.com/andwati/zitadel.git
synced 2026-12-06 10:58:48 +00:00
fix: Registration Form Legal Checkbox Logic (#10597)
Closes #10498 The registration form's legal checkboxes had incorrect validation logic that prevented users from completing registration when only one legal document (ToS or Privacy Policy) was configured, or when no legal documents were required. additionally removes a duplicate description for "or use Identity Provider" # Which Problems Are Solved Having only partial legal documents was blocking users to register. The logic now conditionally renders checkboxes and checks if all provided documents are accepted. # How the Problems Are Solved - Fixed checkbox validation: Now properly validates based on which legal documents are actually available - acceptance logic: Only requires acceptance of checkboxes that are shown - No legal docs support: Users can proceed when no legal documents are configured - Proper state management: Fixed checkbox state tracking and mixed-up test IDs --------- Co-authored-by: Stefan Benz <[email protected]>
This commit is contained in:
co-authored by
Stefan Benz
parent
a0c3ccecf7
commit
b9b9baf67f
@@ -222,7 +222,6 @@
|
|||||||
"termsOfService": "Nutzungsbedingungen",
|
"termsOfService": "Nutzungsbedingungen",
|
||||||
"privacyPolicy": "Datenschutzrichtlinie",
|
"privacyPolicy": "Datenschutzrichtlinie",
|
||||||
"submit": "Weiter",
|
"submit": "Weiter",
|
||||||
"orUseIDP": "oder verwenden Sie einen Identitätsanbieter",
|
|
||||||
"password": {
|
"password": {
|
||||||
"title": "Passwort festlegen",
|
"title": "Passwort festlegen",
|
||||||
"description": "Legen Sie das Passwort für Ihr Konto fest",
|
"description": "Legen Sie das Passwort für Ihr Konto fest",
|
||||||
|
|||||||
@@ -222,7 +222,6 @@
|
|||||||
"termsOfService": "Terms of Service",
|
"termsOfService": "Terms of Service",
|
||||||
"privacyPolicy": "Privacy Policy",
|
"privacyPolicy": "Privacy Policy",
|
||||||
"submit": "Continue",
|
"submit": "Continue",
|
||||||
"orUseIDP": "or use an Identity Provider",
|
|
||||||
"password": {
|
"password": {
|
||||||
"title": "Set Password",
|
"title": "Set Password",
|
||||||
"description": "Set the password for your account",
|
"description": "Set the password for your account",
|
||||||
|
|||||||
@@ -222,7 +222,6 @@
|
|||||||
"termsOfService": "Términos de Servicio",
|
"termsOfService": "Términos de Servicio",
|
||||||
"privacyPolicy": "Política de Privacidad",
|
"privacyPolicy": "Política de Privacidad",
|
||||||
"submit": "Continuar",
|
"submit": "Continuar",
|
||||||
"orUseIDP": "o usa un Proveedor de Identidad",
|
|
||||||
"password": {
|
"password": {
|
||||||
"title": "Establecer Contraseña",
|
"title": "Establecer Contraseña",
|
||||||
"description": "Establece la contraseña para tu cuenta",
|
"description": "Establece la contraseña para tu cuenta",
|
||||||
|
|||||||
@@ -222,7 +222,6 @@
|
|||||||
"termsOfService": "Termini di Servizio",
|
"termsOfService": "Termini di Servizio",
|
||||||
"privacyPolicy": "Informativa sulla Privacy",
|
"privacyPolicy": "Informativa sulla Privacy",
|
||||||
"submit": "Continua",
|
"submit": "Continua",
|
||||||
"orUseIDP": "o usa un Identity Provider",
|
|
||||||
"password": {
|
"password": {
|
||||||
"title": "Imposta Password",
|
"title": "Imposta Password",
|
||||||
"description": "Imposta la password per il tuo account",
|
"description": "Imposta la password per il tuo account",
|
||||||
|
|||||||
@@ -222,7 +222,6 @@
|
|||||||
"termsOfService": "Regulamin",
|
"termsOfService": "Regulamin",
|
||||||
"privacyPolicy": "Polityka prywatności",
|
"privacyPolicy": "Polityka prywatności",
|
||||||
"submit": "Kontynuuj",
|
"submit": "Kontynuuj",
|
||||||
"orUseIDP": "lub użyj dostawcy tożsamości",
|
|
||||||
"password": {
|
"password": {
|
||||||
"title": "Ustaw hasło",
|
"title": "Ustaw hasło",
|
||||||
"description": "Ustaw hasło dla swojego konta",
|
"description": "Ustaw hasło dla swojego konta",
|
||||||
|
|||||||
@@ -222,7 +222,6 @@
|
|||||||
"termsOfService": "Условия использования",
|
"termsOfService": "Условия использования",
|
||||||
"privacyPolicy": "Политика конфиденциальности",
|
"privacyPolicy": "Политика конфиденциальности",
|
||||||
"submit": "Продолжить",
|
"submit": "Продолжить",
|
||||||
"orUseIDP": "или используйте Identity Provider",
|
|
||||||
"password": {
|
"password": {
|
||||||
"title": "Установить пароль",
|
"title": "Установить пароль",
|
||||||
"description": "Установите пароль для вашего аккаунта",
|
"description": "Установите пароль для вашего аккаунта",
|
||||||
|
|||||||
@@ -222,7 +222,6 @@
|
|||||||
"termsOfService": "服务条款",
|
"termsOfService": "服务条款",
|
||||||
"privacyPolicy": "隐私政策",
|
"privacyPolicy": "隐私政策",
|
||||||
"submit": "继续",
|
"submit": "继续",
|
||||||
"orUseIDP": "或使用身份提供者",
|
|
||||||
"password": {
|
"password": {
|
||||||
"title": "设置密码",
|
"title": "设置密码",
|
||||||
"description": "为您的账户设置密码",
|
"description": "为您的账户设置密码",
|
||||||
|
|||||||
@@ -20,12 +20,10 @@ import { headers } from "next/headers";
|
|||||||
|
|
||||||
export async function generateMetadata(): Promise<Metadata> {
|
export async function generateMetadata(): Promise<Metadata> {
|
||||||
const t = await getTranslations("register");
|
const t = await getTranslations("register");
|
||||||
return { title: t('title')};
|
return { title: t("title") };
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function Page(props: {
|
export default async function Page(props: { searchParams: Promise<Record<string | number | symbol, string | undefined>> }) {
|
||||||
searchParams: Promise<Record<string | number | symbol, string | undefined>>;
|
|
||||||
}) {
|
|
||||||
const searchParams = await props.searchParams;
|
const searchParams = await props.searchParams;
|
||||||
|
|
||||||
let { firstname, lastname, email, organization, requestId } = searchParams;
|
let { firstname, lastname, email, organization, requestId } = searchParams;
|
||||||
@@ -104,12 +102,9 @@ export default async function Page(props: {
|
|||||||
{legal &&
|
{legal &&
|
||||||
passwordComplexitySettings &&
|
passwordComplexitySettings &&
|
||||||
organization &&
|
organization &&
|
||||||
(loginSettings.allowUsernamePassword ||
|
(loginSettings.allowUsernamePassword || loginSettings.passkeysType == PasskeysType.ALLOWED) && (
|
||||||
loginSettings.passkeysType == PasskeysType.ALLOWED) && (
|
|
||||||
<RegisterForm
|
<RegisterForm
|
||||||
idpCount={
|
idpCount={!loginSettings?.allowExternalIdp ? 0 : identityProviders.length}
|
||||||
!loginSettings?.allowExternalIdp ? 0 : identityProviders.length
|
|
||||||
}
|
|
||||||
legal={legal}
|
legal={legal}
|
||||||
organization={organization}
|
organization={organization}
|
||||||
firstname={firstname}
|
firstname={firstname}
|
||||||
@@ -122,12 +117,6 @@ export default async function Page(props: {
|
|||||||
|
|
||||||
{loginSettings?.allowExternalIdp && !!identityProviders.length && (
|
{loginSettings?.allowExternalIdp && !!identityProviders.length && (
|
||||||
<>
|
<>
|
||||||
<div className="flex flex-col items-center py-3">
|
|
||||||
<p className="ztdl-p text-center">
|
|
||||||
<Translated i18nKey="orUseIDP" namespace="register" />
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<SignInWithIdp
|
<SignInWithIdp
|
||||||
identityProviders={identityProviders}
|
identityProviders={identityProviders}
|
||||||
requestId={requestId}
|
requestId={requestId}
|
||||||
|
|||||||
@@ -21,6 +21,18 @@ export function PrivacyPolicyCheckboxes({ legal, onChange }: Props) {
|
|||||||
privacyPolicyAccepted: false,
|
privacyPolicyAccepted: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Helper function to check if all required checkboxes are accepted
|
||||||
|
const checkAllAccepted = (newState: AcceptanceState) => {
|
||||||
|
const hasTosLink = !!legal?.tosLink;
|
||||||
|
const hasPrivacyLink = !!legal?.privacyPolicyLink;
|
||||||
|
|
||||||
|
// Check that all required checkboxes are accepted
|
||||||
|
return (
|
||||||
|
(!hasTosLink || newState.tosAccepted) &&
|
||||||
|
(!hasPrivacyLink || newState.privacyPolicyAccepted)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<p className="mt-4 flex flex-row items-center text-sm text-text-light-secondary-500 dark:text-text-dark-secondary-500">
|
<p className="mt-4 flex flex-row items-center text-sm text-text-light-secondary-500 dark:text-text-dark-secondary-500">
|
||||||
@@ -50,16 +62,17 @@ export function PrivacyPolicyCheckboxes({ legal, onChange }: Props) {
|
|||||||
<div className="mt-4 flex items-center">
|
<div className="mt-4 flex items-center">
|
||||||
<Checkbox
|
<Checkbox
|
||||||
className="mr-4"
|
className="mr-4"
|
||||||
checked={false}
|
checked={acceptanceState.tosAccepted}
|
||||||
value={"privacypolicy"}
|
value={"tos"}
|
||||||
onChangeVal={(checked: boolean) => {
|
onChangeVal={(checked: boolean) => {
|
||||||
setAcceptanceState({
|
const newState = {
|
||||||
...acceptanceState,
|
...acceptanceState,
|
||||||
tosAccepted: checked,
|
tosAccepted: checked,
|
||||||
});
|
};
|
||||||
onChange(checked && acceptanceState.privacyPolicyAccepted);
|
setAcceptanceState(newState);
|
||||||
|
onChange(checkAllAccepted(newState));
|
||||||
}}
|
}}
|
||||||
data-testid="privacy-policy-checkbox"
|
data-testid="tos-checkbox"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div className="mr-4 w-[28rem]">
|
<div className="mr-4 w-[28rem]">
|
||||||
@@ -75,25 +88,22 @@ export function PrivacyPolicyCheckboxes({ legal, onChange }: Props) {
|
|||||||
<div className="mt-4 flex items-center">
|
<div className="mt-4 flex items-center">
|
||||||
<Checkbox
|
<Checkbox
|
||||||
className="mr-4"
|
className="mr-4"
|
||||||
checked={false}
|
checked={acceptanceState.privacyPolicyAccepted}
|
||||||
value={"tos"}
|
value={"privacypolicy"}
|
||||||
onChangeVal={(checked: boolean) => {
|
onChangeVal={(checked: boolean) => {
|
||||||
setAcceptanceState({
|
const newState = {
|
||||||
...acceptanceState,
|
...acceptanceState,
|
||||||
privacyPolicyAccepted: checked,
|
privacyPolicyAccepted: checked,
|
||||||
});
|
};
|
||||||
onChange(checked && acceptanceState.tosAccepted);
|
setAcceptanceState(newState);
|
||||||
|
onChange(checkAllAccepted(newState));
|
||||||
}}
|
}}
|
||||||
data-testid="tos-checkbox"
|
data-testid="privacy-policy-checkbox"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div className="mr-4 w-[28rem]">
|
<div className="mr-4 w-[28rem]">
|
||||||
<p className="text-sm text-text-light-500 dark:text-text-dark-500">
|
<p className="text-sm text-text-light-500 dark:text-text-dark-500">
|
||||||
<Link
|
<Link href={legal.privacyPolicyLink} className="underline" target="_blank">
|
||||||
href={legal.privacyPolicyLink}
|
|
||||||
className="underline"
|
|
||||||
target="_blank"
|
|
||||||
>
|
|
||||||
<Translated i18nKey="privacyPolicy" namespace="register" />
|
<Translated i18nKey="privacyPolicy" namespace="register" />
|
||||||
</Link>
|
</Link>
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
@@ -2,20 +2,13 @@
|
|||||||
|
|
||||||
import { registerUser } 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 {
|
import { LoginSettings, PasskeysType } from "@zitadel/proto/zitadel/settings/v2/login_settings_pb";
|
||||||
LoginSettings,
|
|
||||||
PasskeysType,
|
|
||||||
} from "@zitadel/proto/zitadel/settings/v2/login_settings_pb";
|
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
import { FieldValues, useForm } from "react-hook-form";
|
import { FieldValues, useForm } from "react-hook-form";
|
||||||
import { Alert, AlertType } from "./alert";
|
import { Alert, AlertType } from "./alert";
|
||||||
import {
|
import { AuthenticationMethod, AuthenticationMethodRadio, methods } from "./authentication-method-radio";
|
||||||
AuthenticationMethod,
|
|
||||||
AuthenticationMethodRadio,
|
|
||||||
methods,
|
|
||||||
} from "./authentication-method-radio";
|
|
||||||
import { BackButton } from "./back-button";
|
import { BackButton } from "./back-button";
|
||||||
import { Button, ButtonVariants } from "./button";
|
import { Button, ButtonVariants } from "./button";
|
||||||
import { TextInput } from "./input";
|
import { TextInput } from "./input";
|
||||||
@@ -98,10 +91,7 @@ export function RegisterForm({
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function submitAndContinue(
|
async function submitAndContinue(value: Inputs, withPassword: boolean = false) {
|
||||||
value: Inputs,
|
|
||||||
withPassword: boolean = false,
|
|
||||||
) {
|
|
||||||
const registerParams: any = value;
|
const registerParams: any = value;
|
||||||
|
|
||||||
if (organization) {
|
if (organization) {
|
||||||
@@ -114,9 +104,7 @@ export function RegisterForm({
|
|||||||
|
|
||||||
// redirect user to /register/password if password is chosen
|
// redirect user to /register/password if password is chosen
|
||||||
if (withPassword) {
|
if (withPassword) {
|
||||||
return router.push(
|
return router.push(`/register/password?` + new URLSearchParams(registerParams));
|
||||||
`/register/password?` + new URLSearchParams(registerParams),
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
return submitAndRegister(value);
|
return submitAndRegister(value);
|
||||||
}
|
}
|
||||||
@@ -125,6 +113,11 @@ export function RegisterForm({
|
|||||||
const { errors } = formState;
|
const { errors } = formState;
|
||||||
|
|
||||||
const [tosAndPolicyAccepted, setTosAndPolicyAccepted] = useState(false);
|
const [tosAndPolicyAccepted, setTosAndPolicyAccepted] = useState(false);
|
||||||
|
|
||||||
|
// Check if legal acceptance is required
|
||||||
|
const isLegalAcceptanceRequired = !!(legal?.tosLink || legal?.privacyPolicyLink);
|
||||||
|
const canSubmit = formState.isValid && (!isLegalAcceptanceRequired || tosAndPolicyAccepted);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form className="w-full">
|
<form className="w-full">
|
||||||
<div className="mb-4 grid grid-cols-2 gap-4">
|
<div className="mb-4 grid grid-cols-2 gap-4">
|
||||||
@@ -162,38 +155,27 @@ export function RegisterForm({
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{legal && (
|
{(legal?.tosLink || legal?.privacyPolicyLink) && (
|
||||||
<PrivacyPolicyCheckboxes
|
<PrivacyPolicyCheckboxes legal={legal} onChange={setTosAndPolicyAccepted} />
|
||||||
legal={legal}
|
|
||||||
onChange={setTosAndPolicyAccepted}
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
{/* show chooser if both methods are allowed */}
|
{/* show chooser if both methods are allowed */}
|
||||||
{loginSettings &&
|
{loginSettings && loginSettings.allowUsernamePassword && loginSettings.passkeysType == PasskeysType.ALLOWED && (
|
||||||
loginSettings.allowUsernamePassword &&
|
<>
|
||||||
loginSettings.passkeysType == PasskeysType.ALLOWED && (
|
<p className="ztdl-p mb-6 mt-4 block text-left">
|
||||||
<>
|
<Translated i18nKey="selectMethod" namespace="register" />
|
||||||
<p className="ztdl-p mb-6 mt-4 block text-left">
|
</p>
|
||||||
<Translated i18nKey="selectMethod" namespace="register" />
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div className="pb-4">
|
<div className="pb-4">
|
||||||
<AuthenticationMethodRadio
|
<AuthenticationMethodRadio selected={selected} selectionChanged={setSelected} />
|
||||||
selected={selected}
|
</div>
|
||||||
selectionChanged={setSelected}
|
</>
|
||||||
/>
|
)}
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
{!loginSettings?.allowUsernamePassword &&
|
{!loginSettings?.allowUsernamePassword &&
|
||||||
loginSettings?.passkeysType !== PasskeysType.ALLOWED &&
|
loginSettings?.passkeysType !== PasskeysType.ALLOWED &&
|
||||||
(!loginSettings?.allowExternalIdp || !idpCount) && (
|
(!loginSettings?.allowExternalIdp || !idpCount) && (
|
||||||
<div className="py-4">
|
<div className="py-4">
|
||||||
<Alert type={AlertType.INFO}>
|
<Alert type={AlertType.INFO}>
|
||||||
<Translated
|
<Translated i18nKey="noMethodAvailableWarning" namespace="register" />
|
||||||
i18nKey="noMethodAvailableWarning"
|
|
||||||
namespace="register"
|
|
||||||
/>
|
|
||||||
</Alert>
|
</Alert>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@@ -209,11 +191,10 @@ export function RegisterForm({
|
|||||||
<Button
|
<Button
|
||||||
type="submit"
|
type="submit"
|
||||||
variant={ButtonVariants.Primary}
|
variant={ButtonVariants.Primary}
|
||||||
disabled={loading || !formState.isValid || !tosAndPolicyAccepted}
|
disabled={loading || !canSubmit}
|
||||||
onClick={handleSubmit((values) => {
|
onClick={handleSubmit((values) => {
|
||||||
const usePasswordToContinue: boolean =
|
const usePasswordToContinue: boolean =
|
||||||
loginSettings?.allowUsernamePassword &&
|
loginSettings?.allowUsernamePassword && loginSettings?.passkeysType == PasskeysType.ALLOWED
|
||||||
loginSettings?.passkeysType == PasskeysType.ALLOWED
|
|
||||||
? !(selected === methods[0]) // choose selection if both available
|
? !(selected === methods[0]) // choose selection if both available
|
||||||
: !!loginSettings?.allowUsernamePassword; // if password is chosen
|
: !!loginSettings?.allowUsernamePassword; // if password is chosen
|
||||||
// set password as default if only password is allowed
|
// set password as default if only password is allowed
|
||||||
|
|||||||
+2542
-2549
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user