fix 修复 userId 无法获取问题

2.X
疯狂的狮子Li 2 years ago
parent 95fc67e577
commit d6edc56d0e

@ -1,6 +1,7 @@
package com.ruoyi.common.satoken.utils;
import cn.dev33.satoken.context.SaHolder;
import cn.dev33.satoken.context.model.SaStorage;
import cn.dev33.satoken.stp.SaLoginModel;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.convert.Convert;
@ -46,7 +47,9 @@ public class LoginHelper {
* @param loginUser
*/
public static void loginByDevice(LoginUser loginUser, DeviceType deviceType) {
SaHolder.getStorage().set(LOGIN_USER_KEY, loginUser);
SaStorage storage = SaHolder.getStorage();
storage.set(LOGIN_USER_KEY, loginUser);
storage.set(USER_KEY, loginUser.getUserId());
SaLoginModel model = new SaLoginModel();
if (ObjectUtil.isNotNull(deviceType)) {
model.setDevice(deviceType.getDevice());
@ -81,7 +84,11 @@ public class LoginHelper {
public static Long getUserId() {
Long userId;
try {
userId = Convert.toLong(StpUtil.getExtra(USER_KEY));
userId = Convert.toLong(SaHolder.getStorage().get(USER_KEY));
if (ObjectUtil.isNull(userId)) {
userId = Convert.toLong(StpUtil.getExtra(USER_KEY).toString());
SaHolder.getStorage().set(USER_KEY, userId);
}
} catch (Exception e) {
return null;
}

Loading…
Cancel
Save