chore: connect recent logins to back
This commit is contained in:
@@ -12,6 +12,7 @@ import { PageWrapper } from '../PageWrapper';
|
||||
import { PasswordDialog } from './PasswordDialog';
|
||||
import { Toast } from '@/components/Toast';
|
||||
import { regex } from '@/utils/regex';
|
||||
import apiClient from '@/lib/apiClient';
|
||||
|
||||
export function PasswordSecurity() {
|
||||
const theme = useTheme();
|
||||
@@ -53,17 +54,48 @@ export function PasswordSecurity() {
|
||||
const handleOpen = () => setOpen(true);
|
||||
const handleClose = () => setOpen(false);
|
||||
|
||||
const handleShowAlert = () => {
|
||||
setLoading(true);
|
||||
setTimeout(() => {
|
||||
const handleShowAlert = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
|
||||
const url = changePassword
|
||||
? 'Profile/ChangePassword'
|
||||
: 'Profile/AddPassword';
|
||||
|
||||
const payload = changePassword
|
||||
? {
|
||||
oldPassword: currentPassword,
|
||||
newPassword: password,
|
||||
}
|
||||
: {
|
||||
password,
|
||||
confirmPassword,
|
||||
};
|
||||
|
||||
const res = await apiClient.post(url, payload, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${localStorage.getItem('authToken')}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
if (res.data?.success) {
|
||||
setShowPasswordAlert(true);
|
||||
if (!changePassword) setChangePassword(true);
|
||||
handleClose();
|
||||
setPassword('');
|
||||
setConfirmPassword('');
|
||||
setCurrentPassword('');
|
||||
} else {
|
||||
console.error('Password update failed:', res.data?.message);
|
||||
// optionally show error toast
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error updating password:', err);
|
||||
// optionally show error toast
|
||||
} finally {
|
||||
setLoading(false);
|
||||
setShowPasswordAlert(true);
|
||||
setChangePassword(true);
|
||||
handleClose();
|
||||
setPassword('');
|
||||
setConfirmPassword('');
|
||||
setCurrentPassword('');
|
||||
}, 1500);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user