Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/silly-zoos-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/clerk-js': patch
---

Fix sign-up to render legal consent only when required and with no unverified fields
1 change: 1 addition & 0 deletions packages/clerk-js/src/test/fixture-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ const createSignUpFixtureHelpers = (baseClient: ClientJSON) => {
status: 'missing_requirements',
legal_accepted_at: null,
missing_fields: ['legal_accepted'],
unverified_fields: [],
} as SignUpJSON;
};

Expand Down
12 changes: 11 additions & 1 deletion packages/clerk-js/src/ui/components/SignUp/SignUpStart.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getAlternativePhoneCodeProviderData } from '@clerk/shared/alternativePhoneCode';
import { useClerk } from '@clerk/shared/react';
import type { PhoneCodeChannel, PhoneCodeChannelData, SignUpResource } from '@clerk/shared/types';
import React from 'react';
import React, { useMemo } from 'react';

import { isClerkAPIResponseError } from '@/index.headless';
import { Card } from '@/ui/elements/Card';
Expand Down Expand Up @@ -130,6 +130,15 @@ function SignUpStartInternal(): JSX.Element {
const isLegalConsentEnabled = userSettings.signUp.legal_consent_enabled;
const oidcPrompt = ctx.oidcPrompt;

const onlyLegalAcceptedMissing = useMemo(
() =>
signUp.missingFields &&
signUp.missingFields.length === 1 &&
signUp.missingFields[0] === 'legal_accepted' &&
signUp.unverifiedFields &&
signUp.unverifiedFields.length === 0,
[signUp.missingFields, signUp.unverifiedFields],
);
Comment on lines +133 to +141
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already being done on SignUpContinue, but wasn't handled on the root sign-up

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought of moving this check within SignUpForm so we don't repeat the same logic in both pages, however it seems that there was a reason why signUp isn't passed as a prop to it

My assumption is that SignUpForm is for form presentation concerns only and each screen would handle the logic around the sign up object

const fields = determineActiveFields({
attributes,
hasTicket: hasTicket || hasExistingSignUpWithTicket,
Expand Down Expand Up @@ -445,6 +454,7 @@ function SignUpStartInternal(): JSX.Element {
formState={formState}
canToggleEmailPhone={canToggleEmailPhone}
handleEmailPhoneToggle={handleChangeActive}
onlyLegalAcceptedMissing={onlyLegalAcceptedMissing}
/>
)}
</SocialButtonsReversibleContainerWithDivider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,24 @@ describe('SignUpStart', () => {
screen.getByText('Terms of Service');
screen.getByText('Privacy Policy');
});

it('displays legal consent only if included in missing fields without unverified fields', async () => {
const { wrapper } = await createFixtures(f => {
f.withEmailAddress({ required: true });
f.withPassword({ required: true });
f.startSignUpWithMissingLegalAccepted();
f.withLegalConsent();
f.withTermsPrivacyPolicyUrls({
privacyPolicy: 'https://clerk.dev/privacy',
termsOfService: 'https://clerk.dev/tos',
});
});
const { getByText, queryByText } = render(<SignUpStart />, { wrapper });
expect(getByText('Terms of Service')).toBeVisible();
expect(getByText('Privacy Policy')).toBeVisible();
expect(queryByText('Phone number')).not.toBeInTheDocument();
expect(queryByText('Password')).not.toBeInTheDocument();
});
});

describe('ticket flow', () => {
Expand Down
Loading