|
@@ -51,16 +51,20 @@ func Auth(authKey string) gin.HandlerFunc {
|
51
|
51
|
return
|
52
|
52
|
}
|
53
|
53
|
|
54
|
|
- mapClaims := token.Claims.(jwt.MapClaims)
|
55
|
|
- expired := int64(mapClaims[ctxRequestTokenExpired].(float64))
|
56
|
|
- if expired < time.Now().Unix() {
|
57
|
|
- // Only cookie is blank value, check token expired
|
58
|
|
- if _, err := ctx.Cookie(ctxRequestCookieAuthorization); err != nil {
|
59
|
|
- ctx.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"msg": "auth failed, token timeout"})
|
60
|
|
- return
|
|
54
|
+ if mapClaims, ok := token.Claims.(jwt.MapClaims); ok {
|
|
55
|
+ if expired, ok := mapClaims[ctxRequestTokenExpired].(float64); ok {
|
|
56
|
+ if int64(expired) < time.Now().Unix() {
|
|
57
|
+ // Only cookie is blank value, check token expired
|
|
58
|
+ if _, err := ctx.Cookie(ctxRequestCookieAuthorization); err != nil {
|
|
59
|
+ ctx.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"msg": "auth failed, token timeout"})
|
|
60
|
+ return
|
|
61
|
+ }
|
|
62
|
+ }
|
61
|
63
|
}
|
62
|
|
- }
|
63
|
64
|
|
64
|
|
- ctx.Set(CtxRequestHeaderUserId, int(mapClaims[CtxRequestHeaderUserId].(float64)))
|
|
65
|
+ if uid, ok := mapClaims[CtxRequestHeaderUserId].(float64); ok {
|
|
66
|
+ ctx.Set(CtxRequestHeaderUserId, int(uid))
|
|
67
|
+ }
|
|
68
|
+ }
|
65
|
69
|
}
|
66
|
70
|
}
|