mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-07 22:18:33 +00:00
80 lines
2.5 KiB
JavaScript
80 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 { saveCollectionSettings } from 'providers/ReduxStore/slices/collections/actions';
|
|
import StyledWrapper from './StyledWrapper';
|
|
|
|
const WsseAuth = ({ collection }) => {
|
|
const dispatch = useDispatch();
|
|
const { storedTheme } = useTheme();
|
|
|
|
const wsseAuth = collection.draft?.root ? get(collection, 'draft.root.request.auth.wsse', {}) : get(collection, 'root.request.auth.wsse', {});
|
|
const { isSensitive } = useDetectSensitiveField(collection);
|
|
const { showWarning, warningMessage } = isSensitive(wsseAuth?.password);
|
|
|
|
const handleSave = () => dispatch(saveCollectionSettings(collection.uid));
|
|
|
|
const handleUserChange = (username) => {
|
|
dispatch(
|
|
updateCollectionAuth({
|
|
mode: 'wsse',
|
|
collectionUid: collection.uid,
|
|
content: {
|
|
username: username || '',
|
|
password: wsseAuth.password || ''
|
|
}
|
|
})
|
|
);
|
|
};
|
|
|
|
const handlePasswordChange = (password) => {
|
|
dispatch(
|
|
updateCollectionAuth({
|
|
mode: 'wsse',
|
|
collectionUid: collection.uid,
|
|
content: {
|
|
username: wsseAuth.username || '',
|
|
password: password || ''
|
|
}
|
|
})
|
|
);
|
|
};
|
|
|
|
return (
|
|
<StyledWrapper className="mt-2 w-full">
|
|
<label className="block mb-1">Username</label>
|
|
<div className="single-line-editor-wrapper mb-3">
|
|
<SingleLineEditor
|
|
value={wsseAuth.username || ''}
|
|
theme={storedTheme}
|
|
onSave={handleSave}
|
|
onChange={(val) => handleUserChange(val)}
|
|
collection={collection}
|
|
isCompact
|
|
/>
|
|
</div>
|
|
|
|
<label className="block mb-1">Password</label>
|
|
<div className="single-line-editor-wrapper flex items-center">
|
|
<SingleLineEditor
|
|
value={wsseAuth.password || ''}
|
|
theme={storedTheme}
|
|
onSave={handleSave}
|
|
onChange={(val) => handlePasswordChange(val)}
|
|
collection={collection}
|
|
isSecret={true}
|
|
isCompact
|
|
/>
|
|
{showWarning && <SensitiveFieldWarning fieldName="wsse-password" warningMessage={warningMessage} />}
|
|
</div>
|
|
</StyledWrapper>
|
|
);
|
|
};
|
|
|
|
export default WsseAuth;
|