Skip to content
Merged
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
6 changes: 6 additions & 0 deletions .changeset/gold-lamps-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@clerk/clerk-js": minor
"@clerk/types": minor
---

Hide sign up url from `<SignIn />` component when mode is `restricted`
2 changes: 1 addition & 1 deletion packages/clerk-js/bundlewatch.config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"files": [
{ "path": "./dist/clerk.browser.js", "maxSize": "64kB" },
{ "path": "./dist/clerk.browser.js", "maxSize": "64.1kB" },
{ "path": "./dist/clerk.headless.js", "maxSize": "43kB" },
{ "path": "./dist/ui-common*.js", "maxSize": "86KB" },
{ "path": "./dist/vendors*.js", "maxSize": "70KB" },
Expand Down
7 changes: 7 additions & 0 deletions packages/clerk-js/src/core/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { SignUpModes } from '@clerk/types';

// TODO: Do we still have a use for this or can we simply preserve all params?
export const PRESERVED_QUERYSTRING_PARAMS = [
'redirect_url',
Expand Down Expand Up @@ -29,3 +31,8 @@ export const SIGN_IN_INITIAL_VALUE_KEYS = ['email_address', 'phone_number', 'use
export const SIGN_UP_INITIAL_VALUE_KEYS = ['email_address', 'phone_number', 'username', 'first_name', 'last_name'];

export const DEBOUNCE_MS = 350;

export const SIGN_UP_MODES: Record<string, SignUpModes> = {
PUBLIC: 'public',
RESTRICTED: 'restricted',
};
18 changes: 10 additions & 8 deletions packages/clerk-js/src/ui/components/SignIn/SignInStart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isWebAuthnAutofillSupported, isWebAuthnSupported } from '@clerk/shared/
import type { ClerkAPIError, SignInCreateParams, SignInResource } from '@clerk/types';
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';

import { ERROR_CODES } from '../../../core/constants';
import { ERROR_CODES, SIGN_UP_MODES } from '../../../core/constants';
import { clerkInvalidFAPIResponse } from '../../../core/errors';
import { getClerkQueryParam, removeClerkQueryParam } from '../../../utils';
import type { SignInStartIdentifier } from '../../common';
Expand Down Expand Up @@ -410,13 +410,15 @@ export function _SignInStart(): JSX.Element {
</Col>
</Card.Content>
<Card.Footer>
<Card.Action elementId='signIn'>
<Card.ActionText localizationKey={localizationKeys('signIn.start.actionText')} />
<Card.ActionLink
localizationKey={localizationKeys('signIn.start.actionLink')}
to={clerk.buildUrlWithAuth(signUpUrl)}
/>
</Card.Action>
{userSettings.signUp.mode === SIGN_UP_MODES.PUBLIC && (
<Card.Action elementId='signIn'>
<Card.ActionText localizationKey={localizationKeys('signIn.start.actionText')} />
<Card.ActionLink
localizationKey={localizationKeys('signIn.start.actionLink')}
to={clerk.buildUrlWithAuth(signUpUrl)}
/>
</Card.Action>
)}
</Card.Footer>
</Card.Root>
</Flow.Part>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,29 @@ describe('SignInStart', () => {
});
});

describe('Restricted mode', () => {
it('"Don\'t have an account?" text should not be presented', async () => {
const { wrapper } = await createFixtures(f => {
f.withEmailAddress();
f.withRestrictedMode();
});
render(<SignInStart />, { wrapper });
expect(screen.queryByText(/Don’t have an account/i)).not.toBeInTheDocument();
});

it('"Don\'t have an account?" text should be visible', async () => {
const { wrapper, fixtures } = await createFixtures(f => {
f.withEmailAddress();
});
render(<SignInStart />, { wrapper });

const signUpLink = screen.getByText(/Don’t have an account/i).nextElementSibling;
expect(signUpLink?.textContent).toBe('Sign up');
expect(signUpLink?.tagName.toUpperCase()).toBe('A');
expect(signUpLink?.getAttribute('href')).toMatch(fixtures.environment.displayConfig.signUpUrl);
});
});

describe('Social OAuth', () => {
it.each(OAUTH_PROVIDERS)('shows the "Continue with $name" social OAuth button', async ({ provider, name }) => {
const { wrapper } = await createFixtures(f => {
Expand Down
8 changes: 8 additions & 0 deletions packages/clerk-js/src/ui/utils/test/fixtureHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type {
VerificationJSON,
} from '@clerk/types';

import { SIGN_UP_MODES } from '../../../core/constants';
import type { OrgParams } from '../../../core/test/fixtures';
import { createUser, getOrganizationId } from '../../../core/test/fixtures';
import { createUserFixture } from './fixtures';
Expand Down Expand Up @@ -317,6 +318,8 @@ const createUserSettingsFixtureHelpers = (environment: EnvironmentJSON) => {
show_zxcvbn: false,
min_zxcvbn_strength: 0,
};
us.sign_up.mode = SIGN_UP_MODES.PUBLIC;

const emptyAttribute = {
first_factors: [],
second_factors: [],
Expand Down Expand Up @@ -476,6 +479,10 @@ const createUserSettingsFixtureHelpers = (environment: EnvironmentJSON) => {
};
};

const withRestrictedMode = () => {
us.sign_up.mode = SIGN_UP_MODES.RESTRICTED;
};

// TODO: Add the rest, consult pkg/generate/auth_config.go

return {
Expand All @@ -493,5 +500,6 @@ const createUserSettingsFixtureHelpers = (environment: EnvironmentJSON) => {
withAuthenticatorApp,
withPasskey,
withPasskeySettings,
withRestrictedMode,
};
};
3 changes: 3 additions & 0 deletions packages/types/src/userSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,13 @@ export type SignInData = {
};
};

export type SignUpModes = 'public' | 'restricted';

export type SignUpData = {
allowlist_only: boolean;
progressive: boolean;
captcha_enabled: boolean;
mode: SignUpModes;
};

export type PasswordSettingsData = {
Expand Down
17 changes: 11 additions & 6 deletions packages/ui/src/components/sign-in/steps/start.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import { PhoneNumberField } from '~/common/phone-number-field';
import { PhoneNumberOrUsernameField } from '~/common/phone-number-or-username-field';
import { UsernameField } from '~/common/username-field';
import { LOCALIZATION_NEEDED } from '~/constants/localizations';
import { SIGN_UP_MODES } from '~/constants/user-settings';
import { useAppearance } from '~/contexts';
import { useAttributes } from '~/hooks/use-attributes';
import { useCard } from '~/hooks/use-card';
import { useDevModeWarning } from '~/hooks/use-dev-mode-warning';
import { useDisplayConfig } from '~/hooks/use-display-config';
import { useEnabledConnections } from '~/hooks/use-enabled-connections';
import { useEnvironment } from '~/hooks/use-environment';
import { useLocalizations } from '~/hooks/use-localizations';
import { Button } from '~/primitives/button';
import * as Card from '~/primitives/card';
Expand All @@ -27,6 +29,7 @@ import { Separator } from '~/primitives/separator';
export function SignInStart() {
const enabledConnections = useEnabledConnections();
const { t } = useLocalizations();
const { userSettings } = useEnvironment();
const { enabled: usernameEnabled } = useAttributes('username');
const { enabled: phoneNumberEnabled } = useAttributes('phone_number');
const { enabled: emailAddressEnabled } = useAttributes('email_address');
Expand Down Expand Up @@ -184,12 +187,14 @@ export function SignInStart() {
</Card.Content>

<Card.Footer {...footerProps}>
<Card.FooterAction>
<Card.FooterActionText>
{t('signIn.start.actionText')}{' '}
<Card.FooterActionLink href='/sign-up'> {t('signIn.start.actionLink')}</Card.FooterActionLink>
</Card.FooterActionText>
</Card.FooterAction>
{userSettings.signUp.mode === SIGN_UP_MODES.PUBLIC ? (
<Card.FooterAction>
<Card.FooterActionText>
{t('signIn.start.actionText')}{' '}
<Card.FooterActionLink href='/sign-up'> {t('signIn.start.actionLink')}</Card.FooterActionLink>
</Card.FooterActionText>
</Card.FooterAction>
) : null}
</Card.Footer>
</Card.Root>
</SignIn.Step>
Expand Down
6 changes: 6 additions & 0 deletions packages/ui/src/constants/user-settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { SignUpModes } from '@clerk/types';

export const SIGN_UP_MODES: Record<string, SignUpModes> = {
PUBLIC: 'public',
RESTRICTED: 'restricted',
};