diff --git a/app/service/systems/auth/user.js b/app/service/systems/auth/user.js index 8b5916d..77c21f0 100644 --- a/app/service/systems/auth/user.js +++ b/app/service/systems/auth/user.js @@ -1619,8 +1619,13 @@ class UserService extends Service { platform_code: platformCode, }); - // 清理缓存 - await this.clearUserCache(user.id); + // 清理缓存:必须带上 platformCode + // clearUserCache(userId) 不带平台时只清 web/pda/mini/app/workerstation/workstation 这几个硬编码平台, + // 小程序(miniProgram)、微信(wx)等取值不在清单内且 Redis key 大小写敏感,会残留旧身份, + // 导致紧随其后的 findById 命中 5 分钟旧缓存,签发 token / 返回 user 时仍是切换前的角色。 + await this.clearUserCache(user.id, platformCode); + // 同步清理平台激活上下文缓存(platform_active:{accountId}:{platformCode},30 分钟 TTL) + await this.service.systems.accountPlatform.clearPlatformCache(user.id, platformCode); // 获取更新后的用户信息 const userInfo = await this.findById(user.id);