Skip to content

Commit

Permalink
[server] Send 5xx if query to validate token fails (#2695)
Browse files Browse the repository at this point in the history
## Description

## Tests
  • Loading branch information
mnvr authored Aug 14, 2024
2 parents d8b338a + 9d48fa4 commit 62652ea
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions server/pkg/middleware/auth.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package middleware

import (
"database/sql"
"errors"
"fmt"
"github.com/sirupsen/logrus"
"net/http"
"strconv"

Expand Down Expand Up @@ -48,6 +51,11 @@ func (m *AuthMiddleware) TokenAuthMiddleware(jwtClaimScope *jwt.ClaimScope) gin.
userID, err = m.UserController.ValidateJWTToken(token, *jwtClaimScope)
} else {
userID, err = m.UserAuthRepo.GetUserIDWithToken(token, app)
if err != nil && !errors.Is(err, sql.ErrNoRows) {
logrus.Errorf("Failed to validate token: %s", err)
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": "failed to validate token"})
return
}
}
if err != nil {
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "invalid token"})
Expand Down

0 comments on commit 62652ea

Please sign in to comment.