后端logout清除token和refreshToken

This commit is contained in:
2026-04-16 13:31:02 +08:00
parent 5904d209fd
commit a487302946
2 changed files with 14 additions and 0 deletions

View File

@@ -136,6 +136,10 @@ public class UserController {
*/
@PostMapping("/logout")
public Result<Void> logout() {
Long userId = UserContext.getUserId();
if (userId != null) {
userService.logout(userId);
}
return Result.success("退出成功", null);
}
}

View File

@@ -239,6 +239,16 @@ public class UserService extends ServiceImpl<UserMapper, User> {
return fileName;
}
/**
* 退出登录清除token和refreshToken
*/
public void logout(Long userId) {
userMapper.update(null, new LambdaUpdateWrapper<User>()
.eq(User::getId, userId)
.set(User::getToken, null)
.set(User::getRefreshToken, null));
}
/**
* 构建用户信息返回
*/