Skip to content

Commit a9eefc9

Browse files
committed
fix(clerk-js): Render instant password field for password-based instances only
1 parent f72a555 commit a9eefc9

File tree

2 files changed

+41
-21
lines changed

2 files changed

+41
-21
lines changed

packages/clerk-js/src/ui/signIn/SignInStart.test.tsx

+18-3
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ fdescribe('<SignInStart/>', () => {
8989
},
9090
password: {
9191
enabled: true,
92-
used_for_first_factor: false,
92+
required: true,
9393
},
9494
},
9595
social: {
@@ -195,10 +195,10 @@ fdescribe('<SignInStart/>', () => {
195195
expect(instantPasswordField).toBeDefined();
196196

197197
const inputField = screen.getByLabelText('Email address');
198-
await userEvent.type(inputField, 'boss@clerk.dev');
198+
userEvent.type(inputField, 'boss@clerk.dev');
199199

200200
// simulate password being filled by a pwd manager
201-
await userEvent.type(instantPasswordField, 'wrong pass');
201+
userEvent.type(instantPasswordField, 'wrong pass');
202202

203203
const signEmailButton = screen.getByRole('button', { name: /Continue/i });
204204
userEvent.click(signEmailButton);
@@ -271,6 +271,21 @@ fdescribe('<SignInStart/>', () => {
271271
});
272272
});
273273

274+
it('does not render instant password is instance is passwordless', () => {
275+
mockUserSettings = new UserSettings({
276+
attributes: {
277+
password: {
278+
enabled: true,
279+
required: false,
280+
},
281+
},
282+
} as unknown as UserSettingsJSON);
283+
284+
const { container } = render(<SignInStart />);
285+
const instantPasswordField = container.querySelector('input#password') as HTMLInputElement;
286+
expect(instantPasswordField).toBeNull();
287+
});
288+
274289
it.each(['google', 'facebook'])(
275290
'renders the start screen, presses the %s button and starts an oauth flow',
276291
async provider => {

packages/clerk-js/src/ui/signIn/SignInStart.tsx

+23-18
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export function _SignInStart(): JSX.Element {
3939
const standardFormAttributes = userSettings.enabledFirstFactorIdentifiers;
4040
const web3FirstFactors = userSettings.web3FirstFactors;
4141
const socialProviderStrategies = userSettings.socialProviderStrategies;
42+
const passwordBasedInstance = userSettings.instanceIsPasswordBased;
4243

4344
const identifierInputDisplayValues = getIdentifierControlDisplayValues(standardFormAttributes);
4445

@@ -157,24 +158,28 @@ export function _SignInStart(): JSX.Element {
157158
)}
158159
</Control>
159160

160-
<Control
161-
key='password'
162-
htmlFor='password'
163-
label='Password'
164-
error={instantPassword.error}
165-
className={cn({
166-
'cl-hidden': !instantPassword.value,
167-
})}
168-
>
169-
<Input
170-
id='password'
171-
type='password'
172-
name='password'
173-
value={instantPassword.value}
174-
handleChange={el => instantPassword.setValue(el.value || '')}
175-
tabIndex={-1}
176-
/>
177-
</Control>
161+
<>
162+
{passwordBasedInstance && (
163+
<Control
164+
key='password'
165+
htmlFor='password'
166+
label='Password'
167+
error={instantPassword.error}
168+
className={cn({
169+
'cl-hidden': !instantPassword.value,
170+
})}
171+
>
172+
<Input
173+
id='password'
174+
type='password'
175+
name='password'
176+
value={instantPassword.value}
177+
handleChange={el => instantPassword.setValue(el.value || '')}
178+
tabIndex={-1}
179+
/>
180+
</Control>
181+
)}
182+
</>
178183
</Form>
179184
</>
180185
)}

0 commit comments

Comments
 (0)