Paul il y a 6 ans
Parent
révision
226dde51d7
1 fichiers modifiés avec 9 ajouts et 1 suppressions
  1. 9
    1
      middleware/auth/auth.go

+ 9
- 1
middleware/auth/auth.go Voir le fichier

@@ -53,7 +53,15 @@ func Auth(authKey string) gin.HandlerFunc {
53 53
 
54 54
 		if mapClaims, ok := token.Claims.(jwt.MapClaims); ok {
55 55
 			if expired, ok := mapClaims[ctxRequestTokenExpired].(float64); ok {
56
-				if int64(expired) < time.Now().Unix() {
56
+				if expired == 0 {
57
+					// Only cookie is exists, check token expired. app expired by itself call logout when app exit
58
+					if _, err := ctx.Cookie(ctxRequestCookieAuthorization); err != nil {
59
+						ctx.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"msg": "auth failed, token timeout"})
60
+						return
61
+					}
62
+				}
63
+
64
+				if expired < 0 || (int64(expired) < time.Now().Unix()) {
57 65
 					ctx.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"msg": "auth failed, token timeout"})
58 66
 					return
59 67
 				}