Skip to content

Commit

Permalink
fix eddycjy#12 jwt.ValidationErrorExpired
Browse files Browse the repository at this point in the history
  • Loading branch information
eddycjy committed Sep 21, 2018
1 parent 17b5816 commit 85da499
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions middleware/jwt/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package jwt

import (
"net/http"
"time"

"github.com/gin-gonic/gin"
"github.com/dgrijalva/jwt-go"

"github.com/EDDYCJY/go-gin-example/pkg/e"
"github.com/EDDYCJY/go-gin-example/pkg/util"
Expand All @@ -20,11 +20,12 @@ func JWT() gin.HandlerFunc {
if token == "" {
code = e.INVALID_PARAMS
} else {
claims, err := util.ParseToken(token)
if err != nil {
code = e.ERROR_AUTH_CHECK_TOKEN_FAIL
} else if time.Now().Unix() > claims.ExpiresAt {
_, err := util.ParseToken(token)
switch err.(*jwt.ValidationError).Errors {
case jwt.ValidationErrorExpired:
code = e.ERROR_AUTH_CHECK_TOKEN_TIMEOUT
default:
code = e.ERROR_AUTH_CHECK_TOKEN_FAIL
}
}

Expand Down

0 comments on commit 85da499

Please sign in to comment.