Auto-logout when user edits their own username

Co-authored-by: KingIronMan2011 <176780813+KingIronMan2011@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-12-24 00:35:57 +00:00
parent 0013aa428d
commit c0a4ff3c50
2 changed files with 12 additions and 0 deletions

View file

@ -85,6 +85,10 @@ module.exports.userManagementSocketHandler = (socket, server) => {
throw new Error("User not found");
}
// Check if user is editing their own username
const isEditingSelf = (userId === socket.userID);
const usernameChanged = userData.username && userData.username.trim() !== user.username;
// Update user fields
if (userData.username && userData.username.trim() !== user.username) {
// Check if new username already exists
@ -114,6 +118,7 @@ module.exports.userManagementSocketHandler = (socket, server) => {
callback({
ok: true,
msg: "User updated successfully",
requiresLogout: isEditingSelf && usernameChanged,
});
} catch (e) {
log.error("user-management", e.message);

View file

@ -222,6 +222,13 @@ export default {
this.$root.toastSuccess(res.msg);
this.closeDialog();
this.loadUsers();
// If user edited their own username, logout immediately
if (res.requiresLogout) {
setTimeout(() => {
this.$root.logout();
}, 1000);
}
} else {
this.$root.toastError(res.msg);
}