Skip to content

Commit

Permalink
[server] Send 5xx if query to validate token fails
Browse files Browse the repository at this point in the history
  • Loading branch information
ua741 committed Aug 14, 2024
1 parent 49f069c commit 9d48fa4
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 9d48fa4

Please sign in to comment.