jwt.go 514 B

12345678910111213141516171819202122232425
  1. package middleware
  2. import (
  3. "confrontation-training/common"
  4. "confrontation-training/response"
  5. "github.com/gin-gonic/gin"
  6. )
  7. func JwtAuth() gin.HandlerFunc {
  8. return func(context *gin.Context) {
  9. token := context.Request.Header.Get("token")
  10. if token == "" {
  11. response.Failed("非法访问", context)
  12. context.Abort()
  13. return
  14. }
  15. if err := common.VerifyToken(token); err != nil {
  16. response.Failed("登录已过期,请重新登录", context)
  17. context.Abort()
  18. return
  19. }
  20. context.Next()
  21. }
  22. }