Allow all users to change password and handle expired sessions

This commit is contained in:
llpingll committed 2026-01-25 15:19:21 +00:00
1 parent 6e8172c126
commit 4645bde025
4 files changed
+17 -5

No files matched your search

+1 -1
View File
@@ -38,7 +38,7 @@
"react-toastify": "^10.0.5",
"recharts": "2.15.2",
"redux-persist": "6.0.0",
"swr": "2.3.6",
"swr": "^2.3.6",
"vite-plugin-svgr": "^4.2.0",
"zod": "4.1.11"
},
@@ -11,6 +11,8 @@ import { useDispatch, useSelector } from "react-redux";
import { createToast } from "../../../Utils/toastUtils.jsx";
import { getTouchedFieldErrors } from "../../../Validation/error.js";
import { useTranslation } from "react-i18next";
import { useNavigate } from "react-router-dom";
import { clearAuthState } from "../../../Features/Auth/authSlice.js";
const defaultPasswordsState = {
password: "",
@@ -28,11 +30,12 @@ const PasswordPanel = () => {
const theme = useTheme();
const dispatch = useDispatch();
const { t } = useTranslation();
const navigate = useNavigate();
const SPACING_GAP = theme.spacing(12);
//redux state
const { isLoading } = useSelector((state) => state.auth);
const { isLoading, authToken } = useSelector((state) => state.auth);
const idToName = {
"edit-current-password": "password",
@@ -79,6 +82,16 @@ const PasswordPanel = () => {
const handleSubmit = async (event) => {
event.preventDefault();
// Check for expired/invalid token before submitting
if (!authToken) {
createToast({
body: t("passwordPanel.sessionExpired", "Your session has expired. Please log in again."),
});
dispatch(clearAuthState());
navigate("/login");
return;
}
const { error } = newOrChangedCredentials.validate(localData, {
abortEarly: false,
context: { password: localData.newPassword },
@@ -105,7 +118,6 @@ const PasswordPanel = () => {
confirm: "",
});
} else {
// TODO: Check for other errors?
createToast({
body: t(
"passwordPanel.passwordInputIncorrect",
+1 -1
View File
@@ -85,7 +85,7 @@ const Account = ({ open = "profile" }) => {
))}
</CustomTabList>
<ProfilePanel />
{user.role.includes("superadmin") && <PasswordPanel />}
<PasswordPanel />
{!hideTeams && <TeamPanel />}
</TabContext>
</Box>
+1 -1
View File
@@ -555,7 +555,7 @@
"enterNewPassword": "Enter your new password",
"confirmNewPassword": "Confirm new password",
"passwordRequirements": "New password must contain at least 8 characters and must have at least one uppercase letter, one lowercase letter, one number and one special character (!?@#$%^&*()-_=+[]{}|;:'\",./\\~`).",
"saving": "Saving..."
"sessionExpired": "Your session has expired, please log in again to continue."
},
"emailSent": "Email sent successfully",
"failedToSendEmail": "Failed to send email",