fix: return correct error message if user isn't authorized

This commit is contained in:
Elias Schneider
2025-04-28 10:39:17 +02:00
parent 1efd1d182d
commit 86d2b5f59f

View File

@@ -1,7 +1,9 @@
package middleware
import (
"errors"
"github.com/gin-gonic/gin"
"github.com/pocket-id/pocket-id/backend/internal/common"
"github.com/pocket-id/pocket-id/backend/internal/service"
)
@@ -69,6 +71,13 @@ func (m *AuthMiddleware) Add() gin.HandlerFunc {
return
}
// If JWT auth failed and the error is not a NotSignedInError, abort the request
if !errors.Is(err, &common.NotSignedInError{}) {
c.Abort()
_ = c.Error(err)
return
}
// JWT auth failed, try API key auth
userID, isAdmin, err = m.apiKeyMiddleware.Verify(c, m.options.AdminRequired)
if err == nil {