8000 fix(auth): improve error messages in auth by steebchen · Pull Request #367 · hatchet-dev/hatchet · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix(auth): improve error messages in auth #367

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions api/v1/server/authn/middleware.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package authn

import (
"errors"
"fmt"
"net/http"
"strings"
Expand Down Expand Up @@ -107,6 +108,7 @@ func (a *AuthN) handleCookieAuth(c echo.Context) error {

if err != nil {
a.l.Error().Err(err).Msg("error saving unauthenticated session")
return fmt.Errorf("error saving unauthenticated session")
}

return forbidden
Expand All @@ -117,7 +119,7 @@ func (a *AuthN) handleCookieAuth(c echo.Context) error {
if session.IsNew {
if err := saveNewSession(c, session); err != nil {
a.l.Error().Err(err).Msg("error saving unauthenticated session")
return forbidden
return fmt.Errorf("error saving unauthenticated session")
}

c.Set("session", session)
Expand All @@ -139,7 +141,11 @@ func (a *AuthN) handleCookieAuth(c echo.Context) error {
if err != nil {
a.l.Debug().Err(err).Msg("error getting user by id")

return forbidden
if errors.Is(err, db.ErrNotFound) {
return forbidden
}

return fmt.Errorf("error getting user by id: %w", err)
}

// set the user and session in context
Expand All @@ -159,7 +165,7 @@ func (a *AuthN) handleBearerAuth(c echo.Context) error {
if !ok {
a.l.Debug().Msgf("tenant not found in context")

return forbidden
return fmt.Errorf("tenant not found in context")
}

token, err := getBearerTokenFromRequest(c.Request())
Expand Down
0