moved auth into middleware
This commit is contained in:
@@ -29,7 +29,6 @@ func Routes(
|
||||
r gin.IRouter,
|
||||
logger *logging.Logger,
|
||||
sq *sse.Queue,
|
||||
auth *middleware.Auth,
|
||||
) {
|
||||
s := &sseRouter{
|
||||
log: logger,
|
||||
@@ -37,7 +36,7 @@ func Routes(
|
||||
users: make(map[string][maxNumOpenConnectionsPerUser]context.CancelFunc),
|
||||
}
|
||||
|
||||
r.GET("/", auth.AuthenticateAndAddIdentityGin(), response.Handler(s.serveEvents))
|
||||
r.GET("/", response.Handler(s.serveEvents))
|
||||
}
|
||||
|
||||
func (r *sseRouter) serveEvents(c *gin.Context) (response.Response, error) {
|
||||
|
||||
@@ -23,13 +23,12 @@ import (
|
||||
|
||||
type (
|
||||
webpageRouter struct {
|
||||
log *logging.Logger
|
||||
contentDir string
|
||||
templater *templater.Templater
|
||||
rawEvents *raw_events.Store
|
||||
accts *accounts.Store
|
||||
etsy *etsy_platform.Platform
|
||||
authMiddleware *middleware.Auth
|
||||
log *logging.Logger
|
||||
contentDir string
|
||||
templater *templater.Templater
|
||||
rawEvents *raw_events.Store
|
||||
accts *accounts.Store
|
||||
etsy *etsy_platform.Platform
|
||||
}
|
||||
|
||||
// ErrTemplateNotFound is returned if the reason the template failed to compile
|
||||
@@ -41,12 +40,12 @@ type (
|
||||
|
||||
func SetupRoutes(
|
||||
logger *logging.Logger,
|
||||
r gin.IRouter,
|
||||
r gin.IRoutes,
|
||||
contentDir string,
|
||||
rawEvents *raw_events.Store,
|
||||
accts *accounts.Store,
|
||||
etsy *etsy_platform.Platform,
|
||||
authMiddleware *middleware.Auth,
|
||||
auth *middleware.Auth,
|
||||
) {
|
||||
|
||||
s := &webpageRouter{
|
||||
@@ -90,34 +89,13 @@ func SetupRoutes(
|
||||
}
|
||||
},
|
||||
}),
|
||||
rawEvents: rawEvents,
|
||||
accts: accts,
|
||||
etsy: etsy,
|
||||
authMiddleware: authMiddleware,
|
||||
rawEvents: rawEvents,
|
||||
accts: accts,
|
||||
etsy: etsy,
|
||||
}
|
||||
|
||||
authenticate := s.authMiddleware.AuthenticateAndAddIdentityToRequest()
|
||||
|
||||
r.GET("/*rest", response.Handler(func(c *gin.Context) (response.Response, error) {
|
||||
c.Request.URL.Path = c.Request.URL.Path[3:]
|
||||
defer func() {
|
||||
c.Request.URL.Path = "/ui" + c.Request.URL.Path
|
||||
}()
|
||||
|
||||
p := c.Request.URL.Path
|
||||
if p == "/" || p == "" {
|
||||
c, err := s.authMiddleware.AddIdentityToRequest(c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return s.serveTemplate(c)
|
||||
}
|
||||
|
||||
if res, err := authenticate(c); res != nil || err != nil {
|
||||
return res, err
|
||||
}
|
||||
return s.serveTemplate(c)
|
||||
}))
|
||||
r.GET("", response.Handler(s.serveTemplate))
|
||||
r.GET("/*rest", response.Handler(auth.Authenticate()), response.Handler(s.serveTemplate))
|
||||
}
|
||||
|
||||
// GET /
|
||||
|
||||
Reference in New Issue
Block a user