后端logout清除token和refreshToken
This commit is contained in:
@@ -136,6 +136,10 @@ public class UserController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping("/logout")
|
@PostMapping("/logout")
|
||||||
public Result<Void> logout() {
|
public Result<Void> logout() {
|
||||||
|
Long userId = UserContext.getUserId();
|
||||||
|
if (userId != null) {
|
||||||
|
userService.logout(userId);
|
||||||
|
}
|
||||||
return Result.success("退出成功", null);
|
return Result.success("退出成功", null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -239,6 +239,16 @@ public class UserService extends ServiceImpl<UserMapper, User> {
|
|||||||
return fileName;
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建用户信息返回
|
* 构建用户信息返回
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user