Files
bruno/packages/bruno-app/src/components/CollectionSettings/Auth/BasicAuth/index.js
Sanjai Kumar 98c09db820 fix: enable sensitive field warnings for collection and folder auth (#5230)
- Fix sensitive field warnings not showing for collection-level and folder-level auth
- Use consistent object structure approach across all auth levels (collection, folder, request)
- Replace manual object property access with lodash get() for better readability and robustness
- Extract variable usage checking logic into reusable helper function
- Eliminate code duplication by using single sensitive fields definition
- Improve maintainability and performance by reducing regex pattern recreation

feat: add sensitive field warnings to collection-level auth components

refactor: streamline sensitive field checks in environment variables

refactor: remove unused imports in EnvironmentVariables component

Co-authored-by: sanjai0py <sanjailucifer666@gmail.com>
2025-07-31 22:32:37 +05:30

78 lines
2.5 KiB
JavaScript

import React from 'react';
import SensitiveFieldWarning from 'components/SensitiveFieldWarning';
import { useDetectSensitiveField } from 'hooks/useDetectSensitiveField';
import get from 'lodash/get';
import { useTheme } from 'providers/Theme';
import { useDispatch } from 'react-redux';
import SingleLineEditor from 'components/SingleLineEditor';
import { updateCollectionAuth } from 'providers/ReduxStore/slices/collections';
import { saveCollectionRoot } from 'providers/ReduxStore/slices/collections/actions';
import StyledWrapper from './StyledWrapper';
const BasicAuth = ({ collection }) => {
const dispatch = useDispatch();
const { storedTheme } = useTheme();
const basicAuth = get(collection, 'root.request.auth.basic', {});
const { isSensitive } = useDetectSensitiveField(collection);
const { showWarning, warningMessage } = isSensitive(basicAuth?.password);
const handleSave = () => dispatch(saveCollectionRoot(collection.uid));
const handleUsernameChange = (username) => {
dispatch(
updateCollectionAuth({
mode: 'basic',
collectionUid: collection.uid,
content: {
username: username || '',
password: basicAuth.password || ''
}
})
);
};
const handlePasswordChange = (password) => {
dispatch(
updateCollectionAuth({
mode: 'basic',
collectionUid: collection.uid,
content: {
username: basicAuth.username || '',
password: password || ''
}
})
);
};
return (
<StyledWrapper className="mt-2 w-full">
<label className="block font-medium mb-2">Username</label>
<div className="single-line-editor-wrapper mb-2">
<SingleLineEditor
value={basicAuth.username || ''}
theme={storedTheme}
onSave={handleSave}
onChange={(val) => handleUsernameChange(val)}
collection={collection}
/>
</div>
<label className="block font-medium mb-2">Password</label>
<div className="single-line-editor-wrapper flex items-center">
<SingleLineEditor
value={basicAuth.password || ''}
theme={storedTheme}
onSave={handleSave}
onChange={(val) => handlePasswordChange(val)}
collection={collection}
isSecret={true}
/>
{showWarning && <SensitiveFieldWarning fieldName="basic-password" warningMessage={warningMessage} />}
</div>
</StyledWrapper>
);
};
export default BasicAuth;