From 1ca4c26d816181c6dbe9f60ace518b66f62fc62e Mon Sep 17 00:00:00 2001
From: bug制造者 <837099748@qq.com>
Date: Wed, 07 Jul 2021 17:16:05 +0800
Subject: [PATCH] 修改登录失效返回值code401 之前返回的code200,前端就会$message一下错误信息,不会弹出401重新登录跳转的弹框。

---
 ruoyi-gateway/src/main/java/com/ruoyi/gateway/filter/AuthFilter.java |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/ruoyi-gateway/src/main/java/com/ruoyi/gateway/filter/AuthFilter.java b/ruoyi-gateway/src/main/java/com/ruoyi/gateway/filter/AuthFilter.java
index 36c72d6..3771b46 100644
--- a/ruoyi-gateway/src/main/java/com/ruoyi/gateway/filter/AuthFilter.java
+++ b/ruoyi-gateway/src/main/java/com/ruoyi/gateway/filter/AuthFilter.java
@@ -20,6 +20,7 @@
 import com.ruoyi.common.core.constant.CacheConstants;
 import com.ruoyi.common.core.constant.Constants;
 import com.ruoyi.common.core.domain.R;
+import com.ruoyi.common.core.utils.ServletUtils;
 import com.ruoyi.common.core.utils.StringUtils;
 import com.ruoyi.common.redis.service.RedisService;
 import com.ruoyi.gateway.config.properties.IgnoreWhiteProperties;
@@ -78,7 +79,7 @@
         redisService.expire(getTokenKey(token), EXPIRE_TIME);
         // 设置用户信息到请求
         ServerHttpRequest mutableReq = exchange.getRequest().mutate().header(CacheConstants.DETAILS_USER_ID, userid)
-                .header(CacheConstants.DETAILS_USERNAME, username).build();
+                .header(CacheConstants.DETAILS_USERNAME, ServletUtils.urlEncode(username)).build();
         ServerWebExchange mutableExchange = exchange.mutate().request(mutableReq).build();
 
         return chain.filter(mutableExchange);
@@ -94,7 +95,7 @@
 
         return response.writeWith(Mono.fromSupplier(() -> {
             DataBufferFactory bufferFactory = response.bufferFactory();
-            return bufferFactory.wrap(JSON.toJSONBytes(R.fail(msg)));
+            return bufferFactory.wrap(JSON.toJSONBytes(R.fail(HttpStatus.UNAUTHORIZED.value(), msg)));
         }));
     }
 

--
Gitblit v1.9.3