修复首页逻辑
Change-Id: I40573cdba8c536f4ccd1c3c39c8f8ea90c6b211f
diff --git a/Merge/front/src/components/UserProfile.jsx b/Merge/front/src/components/UserProfile.jsx
index 2e54fac..604d83c 100644
--- a/Merge/front/src/components/UserProfile.jsx
+++ b/Merge/front/src/components/UserProfile.jsx
@@ -445,9 +445,15 @@
const handleMenuClose = () => setAnchorEl(null);
const handleLogout = () => {
handleMenuClose();
- // 清理本地存储
+ // 清理本地存储中的token和用户信息
+ localStorage.removeItem('token');
+ localStorage.removeItem('user');
+ localStorage.removeItem('userId');
localStorage.clear();
- // 在此处添加退出登录逻辑,比如清理本地存储并跳转
+
+ showSnackbar('已成功注销', 'success');
+
+ // 跳转到首页
navigate('/login');
};
@@ -579,7 +585,21 @@
</Box>
<Box sx={{ mt: isMobile ? 2 : 0, alignSelf: 'flex-start' }}>
- {!isOwnProfile && currentUser && (
+ {isOwnProfile ? (
+ // 如果是自己的个人资料页面,显示注销按钮
+ <Button
+ variant="outlined"
+ color="error"
+ onClick={handleLogout}
+ sx={{
+ borderRadius: 20,
+ px: 3,
+ fontWeight: 'bold'
+ }}
+ >
+ 注销
+ </Button>
+ ) : currentUser && (
<>
<Button
variant={profileUser.is_following ? "outlined" : "contained"}