always parse authorization token for all request

This commit is contained in:
RockYang 2024-03-20 21:11:52 +08:00
parent 0cbc284e42
commit 264e77f383
2 changed files with 5 additions and 5 deletions

View File

@ -165,21 +165,21 @@ func authorizeMiddleware(s *AppServer, client *redis.Client) gin.HandlerFunc {
})
if err != nil {
if err != nil && needLogin(c) {
resp.NotAuth(c, fmt.Sprintf("Error with parse auth token: %v", err))
c.Abort()
return
}
claims, ok := token.Claims.(jwt.MapClaims)
if !ok || !token.Valid {
if !ok || !token.Valid && needLogin(c) {
resp.NotAuth(c, "Token is invalid")
c.Abort()
return
}
expr := utils.IntValue(utils.InterfaceToString(claims["expired"]), 0)
if expr > 0 && int64(expr) < time.Now().Unix() {
if expr > 0 && int64(expr) < time.Now().Unix() && needLogin(c) {
resp.NotAuth(c, "Token is expired")
c.Abort()
return

View File

@ -1,5 +1,5 @@
VUE_APP_API_HOST=http://172.22.11.200:5678
VUE_APP_WS_HOST=ws://172.22.11.200:5678
VUE_APP_API_HOST=http://localhost:5678
VUE_APP_WS_HOST=ws://localhost:5678
VUE_APP_USER=18575670125
VUE_APP_PASS=12345678
VUE_APP_ADMIN_USER=admin