From 7cdc1cebccc93d16d681af800e3dedd6c9aacfbe Mon Sep 17 00:00:00 2001 From: weizhihong Date: Thu, 7 Sep 2023 14:36:23 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AE=A4=E8=AF=81?= =?UTF-8?q?=E8=AF=B4=E6=98=8E=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- middleware/jwt.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/middleware/jwt.go b/middleware/jwt.go index f38075e..e97c311 100644 --- a/middleware/jwt.go +++ b/middleware/jwt.go @@ -3,6 +3,7 @@ package middleware import ( "log" "strconv" + "strings" "time" jwt "github.com/appleboy/gin-jwt/v2" @@ -56,7 +57,11 @@ func InitGinJwtMiddleware() (authMiddleware *jwt.GinJWTMiddleware) { return user, nil }, Unauthorized: func(c *gin.Context, code int, message string) { - c.JSON(code, gin.H{"code": code, "title": "token过期", "message": message}) + if strings.Contains(message, "token") { + c.JSON(code, gin.H{"code": code, "title": "token过期", "message": message}) + } else { + c.JSON(code, gin.H{"code": code, "title": "登录认证失败", "message": message}) + } }, // Authorizator: func(data interface{}, c *gin.Context) bool { // if v, ok := data.(*model.User); ok && v.Name == "sheng" {