Skip to content

Commit 972d056

Browse files
committed
fix(clerk-js): If password is enabled, instanceIsPasswordBased is true
The Clerk Dashboard now has improved support for enabling an instance configuration with password enabled, but not required. Such a configuration makes passwords optional on sign-up, allows users to add them to accounts, and allows users to use them for sign-in. Previously, passwords were both enabled and required together. If the instance is configured with password enabled but not required, the SDK should still treat the instance as password based. Modify `UserSettings.instanceIsPasswordBased` to return true in this configuration. This (a) makes sure that the password card is displayed on the SecurityPage so that users can modify their passwords, and (b) allows instant password sign in. Fixes USER-3245. Tested with unit testing and with local Clerk. Revised and simplified version of #6592 which modifies `UserSettings.instanceIsPasswordBased` instead of adding a new property.
1 parent c3facf1 commit 972d056

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

.changeset/khaki-ravens-cheer.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
---
4+
5+
Update `UserSettings.instanceIsPasswordBased` to return true if password is enabled but not required.

packages/clerk-js/src/core/resources/UserSettings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ export class UserSettings extends BaseResource implements UserSettingsResource {
191191
}
192192

193193
get instanceIsPasswordBased() {
194-
return Boolean(this.attributes?.password?.enabled && this.attributes.password?.required);
194+
return Boolean(this.attributes?.password?.enabled);
195195
}
196196

197197
get hasValidAuthFactor() {

packages/clerk-js/src/core/resources/__tests__/UserSettings.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ describe('UserSettings', () => {
7575
},
7676
},
7777
} as any as UserSettingsJSON);
78+
79+
expect(sut.instanceIsPasswordBased).toEqual(true);
80+
81+
sut = new UserSettings({
82+
attributes: {
83+
password: {
84+
enabled: false,
85+
required: false,
86+
},
87+
},
88+
} as any as UserSettingsJSON);
89+
7890
expect(sut.instanceIsPasswordBased).toEqual(false);
7991
});
8092

packages/clerk-js/src/ui/components/SignIn/__tests__/SignInStart.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ describe('SignInStart', () => {
437437
it(`calls sign in with identifier again with only the email if the api respondes with the error ${code}`, async () => {
438438
const { wrapper, fixtures } = await createFixtures(f => {
439439
f.withEmailAddress();
440-
f.withPassword({ required: true });
440+
f.withPassword();
441441
});
442442

443443
const errJSON = {

packages/clerk-js/src/ui/components/UserProfile/__tests__/SecurityPage.test.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ describe('SecurityPage', () => {
3232

3333
it('renders the Password section if instance is password based', async () => {
3434
const { wrapper, fixtures } = await createFixtures(f => {
35-
f.withPassword({
36-
required: true,
37-
});
35+
f.withPassword();
3836
f.withUser({ email_addresses: ['[email protected]'] });
3937
});
4038
fixtures.clerk.user?.getSessions.mockReturnValue(Promise.resolve([]));

0 commit comments

Comments
 (0)