Skip to content

Commit

Permalink
fix(server): auth error fix bug (#1459)
Browse files Browse the repository at this point in the history
  • Loading branch information
hexaforce authored Feb 27, 2025
1 parent 6a8820f commit fd3cc37
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions server/internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,22 @@ func initEcho(ctx context.Context, cfg *ServerConfig) *echo.Echo {
}

// auth
authConfig := cfg.Config.JWTProviders()
log.Infof("auth: config: %#v", authConfig)

var wrapHandler func(http.Handler) http.Handler
if cfg.Config.UseMockAuth() {
log.Infof("Using mock auth for local development")
wrapHandler = func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

ctx := r.Context()
ctx = adapter.AttachMockAuth(ctx, true)
next.ServeHTTP(w, r.WithContext(ctx))
})
}
} else {
authConfig := cfg.Config.JWTProviders()
log.Infof("auth: config: %#v", authConfig)
if cfg.Config.AuthSrv.Disabled {
wrapHandler = lo.Must(AuthMiddlewareDummy())
} else {
wrapHandler = lo.Must(appx.AuthMiddleware(authConfig, adapter.ContextAuthInfo, true))
}
wrapHandler = lo.Must(appx.AuthMiddleware(authConfig, adapter.ContextAuthInfo, true))
}

e.Use(echo.WrapMiddleware(wrapHandler))
Expand Down Expand Up @@ -161,12 +159,6 @@ func initEcho(ctx context.Context, cfg *ServerConfig) *echo.Echo {
return e
}

func AuthMiddlewareDummy() (func(http.Handler) http.Handler, error) {
return func(next http.Handler) http.Handler {
return next
}, nil
}

func errorHandler(next func(error, echo.Context)) func(error, echo.Context) {
return func(err error, c echo.Context) {
if c.Response().Committed {
Expand Down

0 comments on commit fd3cc37

Please sign in to comment.