@@ -53,7 +53,7 @@ func (rh RouteHandler[T]) ServeHTTP(w http.ResponseWriter, r *http.Request) {
5353 }
5454}
5555
56- func NewRouter (config * config.Config , pathPrefix string , routes []Route , additionalMiddlewares ... mux.MiddlewareFunc ) * mux.Router {
56+ func NewRouter (config * config.Config , pathPrefix string , routes []Route , authMiddleware AuthMiddlewareFunc , additionalMiddlewares ... mux.MiddlewareFunc ) * mux.Router {
5757 router := mux .NewRouter ()
5858
5959 // Setup default middleware
@@ -74,6 +74,10 @@ func NewRouter(config *config.Config, pathPrefix string, routes []Route, additio
7474
7575 router .Use (hlog .URLHandler ("uri" ))
7676
77+ if authMiddleware == nil {
78+ authMiddleware = DefaultAuthMiddleware
79+ }
80+
7781 // Setup supplied middleware
7882 for _ , additionalMiddleware := range additionalMiddlewares {
7983 router .Use (additionalMiddleware )
@@ -85,7 +89,7 @@ func NewRouter(config *config.Config, pathPrefix string, routes []Route, additio
8589 if route .DisableAuth || config .ApiKey == "" {
8690 router .Handle (routePattern , route .Handler ).Methods (route .Method )
8791 } else {
88- router .Handle (routePattern , AuthMiddleware (route .Handler , config , route .EnableSessionAuth )).Methods (route .Method )
92+ router .Handle (routePattern , authMiddleware (route .Handler , config , route .EnableSessionAuth )).Methods (route .Method )
8993 }
9094 }
9195
0 commit comments