Skip to content

Commit e011ed5

Browse files
icecrasher321claude
andcommitted
fix(chat): correct password-change confirmation gate and stale reveal error
Addresses both open Bugbot findings. - shouldConfirmPasswordChange keyed on "a chat exists" rather than "a password exists", so switching a public chat to password protection for the first time asked the admin to confirm changing a password that was never set. It now takes the existing-password signal the component already computes. - A failed reveal left "Failed to load the current password" on screen while the admin typed or generated a replacement, because the mutation only drops its error on the next attempt. Editing or regenerating now resets it. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent e50777f commit e011ed5

3 files changed

Lines changed: 26 additions & 5 deletions

File tree

  • apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/deploy/components/deploy-modal/components/chat

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/deploy/components/deploy-modal/components/chat/chat.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ export function ChatDeploy({
245245

246246
if (
247247
!passwordChangeConfirmed &&
248-
shouldConfirmPasswordChange(Boolean(existingChat?.id), formData.authType, formData.password)
248+
shouldConfirmPasswordChange(existingPassword, formData.authType, formData.password)
249249
) {
250250
setShowPasswordChangeConfirmation(true)
251251
return
@@ -700,6 +700,16 @@ function AuthSelector({
700700
const emailsRef = useRef(emails)
701701
const invalidEmailItemsRef = useRef(invalidEmailItems)
702702

703+
/**
704+
* Editing or regenerating the password clears a failed reveal. The mutation
705+
* only drops its error on the next attempt, so it would otherwise keep
706+
* reporting a stale failure over a field the admin has already moved on from.
707+
*/
708+
const handlePasswordChange = (value: string) => {
709+
if (revealPasswordMutation.isError) revealPasswordMutation.reset()
710+
onPasswordChange(value)
711+
}
712+
703713
useEffect(() => {
704714
emailsRef.current = emails
705715
}, [emails])
@@ -799,7 +809,7 @@ function AuthSelector({
799809
</Label>
800810
<GeneratedPasswordInput
801811
value={password}
802-
onChange={onPasswordChange}
812+
onChange={handlePasswordChange}
803813
disabled={disabled}
804814
placeholder={hasExistingPassword ? '' : getPasswordPlaceholder(false)}
805815
required={!hasExistingPassword}

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/deploy/components/deploy-modal/components/chat/utils.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,16 @@ describe.concurrent('chat password state', () => {
3838
expect(getPasswordHelperText(false)).toBe('This password will be required to access your chat')
3939
})
4040

41-
it('confirms a password change only for an existing password deployment with a new value', () => {
41+
it('confirms only when a stored password is actually being replaced', () => {
4242
expect(shouldConfirmPasswordChange(true, 'password', 'new-password')).toBe(true)
4343
expect(shouldConfirmPasswordChange(true, 'password', '')).toBe(false)
4444
expect(shouldConfirmPasswordChange(true, 'password', ' ')).toBe(false)
4545
expect(shouldConfirmPasswordChange(true, 'public', 'new-password')).toBe(false)
46+
})
47+
48+
it('does not confirm when the deployment has no password to replace', () => {
4649
expect(shouldConfirmPasswordChange(false, 'password', 'new-password')).toBe(false)
50+
expect(hasExistingPassword({ authType: 'public', hasPassword: false })).toBe(false)
51+
expect(hasExistingPassword({ authType: 'password', hasPassword: true })).toBe(true)
4752
})
4853
})

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/deploy/components/deploy-modal/components/chat/utils.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,18 @@ export function isWhitespaceOnlyPassword(password: string): boolean {
2323
return password.length > 0 && password.trim().length === 0
2424
}
2525

26+
/**
27+
* Whether submitting should confirm before overwriting the stored password.
28+
* Only a genuine replacement warrants the prompt — keying this on "a chat
29+
* exists" asked an admin to confirm changing a password that was never set,
30+
* e.g. when switching a public chat to password protection for the first time.
31+
*/
2632
export function shouldConfirmPasswordChange(
27-
hasExistingChat: boolean,
33+
existingPassword: boolean,
2834
authType: AuthType,
2935
password: string
3036
): boolean {
31-
return hasExistingChat && authType === 'password' && password.trim().length > 0
37+
return existingPassword && authType === 'password' && password.trim().length > 0
3238
}
3339

3440
export function getPasswordPlaceholder(existingPassword: boolean): string {

0 commit comments

Comments
 (0)