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", "react-toastify": "^10.0.5",
"recharts": "2.15.2", "recharts": "2.15.2",
"redux-persist": "6.0.0", "redux-persist": "6.0.0",
"swr": "2.3.6", "swr": "^2.3.6",
"vite-plugin-svgr": "^4.2.0", "vite-plugin-svgr": "^4.2.0",
"zod": "4.1.11" "zod": "4.1.11"
}, },
@@ -11,6 +11,8 @@ import { useDispatch, useSelector } from "react-redux";
import { createToast } from "../../../Utils/toastUtils.jsx"; import { createToast } from "../../../Utils/toastUtils.jsx";
import { getTouchedFieldErrors } from "../../../Validation/error.js"; import { getTouchedFieldErrors } from "../../../Validation/error.js";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { useNavigate } from "react-router-dom";
import { clearAuthState } from "../../../Features/Auth/authSlice.js";
const defaultPasswordsState = { const defaultPasswordsState = {
password: "", password: "",
@@ -28,11 +30,12 @@ const PasswordPanel = () => {
const theme = useTheme(); const theme = useTheme();
const dispatch = useDispatch(); const dispatch = useDispatch();
const { t } = useTranslation(); const { t } = useTranslation();
const navigate = useNavigate();
const SPACING_GAP = theme.spacing(12); const SPACING_GAP = theme.spacing(12);
//redux state //redux state
const { isLoading } = useSelector((state) => state.auth); const { isLoading, authToken } = useSelector((state) => state.auth);
const idToName = { const idToName = {
"edit-current-password": "password", "edit-current-password": "password",
@@ -79,6 +82,16 @@ const PasswordPanel = () => {
const handleSubmit = async (event) => { const handleSubmit = async (event) => {
event.preventDefault(); 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, { const { error } = newOrChangedCredentials.validate(localData, {
abortEarly: false, abortEarly: false,
context: { password: localData.newPassword }, context: { password: localData.newPassword },
@@ -105,7 +118,6 @@ const PasswordPanel = () => {
confirm: "", confirm: "",
}); });
} else { } else {
// TODO: Check for other errors?
createToast({ createToast({
body: t( body: t(
"passwordPanel.passwordInputIncorrect", "passwordPanel.passwordInputIncorrect",
+1 -1
View File
@@ -85,7 +85,7 @@ const Account = ({ open = "profile" }) => {
))} ))}
</CustomTabList> </CustomTabList>
<ProfilePanel /> <ProfilePanel />
{user.role.includes("superadmin") && <PasswordPanel />} <PasswordPanel />
{!hideTeams && <TeamPanel />} {!hideTeams && <TeamPanel />}
</TabContext> </TabContext>
</Box> </Box>
+1 -1
View File
@@ -555,7 +555,7 @@
"enterNewPassword": "Enter your new password", "enterNewPassword": "Enter your new password",
"confirmNewPassword": "Confirm 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 (!?@#$%^&*()-_=+[]{}|;:'\",./\\~`).", "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", "emailSent": "Email sent successfully",
"failedToSendEmail": "Failed to send email", "failedToSendEmail": "Failed to send email",