diff --git a/frontend/src/components/settings/general/GeneralContainer.jsx b/frontend/src/components/settings/general/GeneralContainer.jsx
index 86d1449..39d65f2 100644
--- a/frontend/src/components/settings/general/GeneralContainer.jsx
+++ b/frontend/src/components/settings/general/GeneralContainer.jsx
@@ -17,6 +17,8 @@ const GeneralContainer = () => {
const [showCurrentPassword, setShowCurrentPassword] = useState(false);
const [showUsernameCurrentPassword, setShowUsernameCurrentPassword] =
useState(false);
+ const [showApiKeyCurrentPassword, setShowApiKeyCurrentPassword] =
+ useState(false);
const [copySuccess, setCopySuccess] = useState(false);
const [formData, setFormData] = useState({
apiKey: '',
@@ -25,7 +27,8 @@ const GeneralContainer = () => {
password: '',
confirmPassword: '',
currentPassword: '',
- currentUsername: ''
+ currentUsername: '',
+ apiKeyCurrentPassword: ''
});
useEffect(() => {
@@ -44,7 +47,8 @@ const GeneralContainer = () => {
usernameCurrentPassword: '',
password: '',
confirmPassword: '',
- currentPassword: ''
+ currentPassword: '',
+ apiKeyCurrentPassword: ''
}));
} catch (error) {
console.error('Error fetching settings:', error);
@@ -60,16 +64,26 @@ const GeneralContainer = () => {
};
const handleResetApiKey = async () => {
+ if (!formData.apiKeyCurrentPassword) {
+ Alert.error(
+ 'Please enter your current password to reset the API key.'
+ );
+ return;
+ }
+
const confirmed = window.confirm(
'Are you sure you want to reset your API key? This action cannot be undone and your current key will stop working immediately.'
);
if (confirmed) {
try {
- const response = await resetApiKey(formData.currentPassword);
+ const response = await resetApiKey(
+ formData.apiKeyCurrentPassword
+ );
setFormData(prev => ({
...prev,
- apiKey: response.api_key
+ apiKey: response.api_key,
+ apiKeyCurrentPassword: ''
}));
} catch (error) {
console.error('Error resetting API key:', error);
@@ -113,6 +127,13 @@ const GeneralContainer = () => {
}));
};
+ const handleApiKeyCurrentPasswordChange = e => {
+ setFormData(prev => ({
+ ...prev,
+ apiKeyCurrentPassword: e.target.value
+ }));
+ };
+
const handleSaveUsername = async () => {
try {
await updateUsername(
@@ -210,6 +231,31 @@ const GeneralContainer = () => {