Skip to content

Commit

Permalink
chore: rename to validatenodemiddleware
Browse files Browse the repository at this point in the history
  • Loading branch information
im-adithya committed Jan 23, 2024
1 parent e51f0ea commit 84a1a5c
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions echo_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,18 @@ import (

// TODO: echo methods should not be on Service object

func (svc *Service) ValidateUserMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
func (svc *Service) ValidateAuthMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
if svc.lnClient == nil {
return c.JSON(http.StatusMethodNotAllowed, ErrorResponse{
Message: "Lightning Client not initialized",
})
}
return next(c)
}
}

func (svc *Service) ValidateNodeMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
if svc.lnClient == nil {
return c.JSON(http.StatusMethodNotAllowed, ErrorResponse{
Expand All @@ -38,11 +49,11 @@ func (svc *Service) RegisterSharedRoutes(e *echo.Echo) {
}))
e.Use(session.Middleware(sessions.NewCookieStore([]byte(svc.cfg.CookieSecret))))

authMiddleware := svc.ValidateUserMiddleware
e.GET("/api/apps", svc.AppsListHandler, authMiddleware)
e.GET("/api/apps/:pubkey", svc.AppsShowHandler, authMiddleware)
e.DELETE("/api/apps/:pubkey", svc.AppsDeleteHandler, authMiddleware)
e.POST("/api/apps", svc.AppsCreateHandler, authMiddleware)
nodeMiddleware := svc.ValidateNodeMiddleware
e.GET("/api/apps", svc.AppsListHandler, nodeMiddleware)
e.GET("/api/apps/:pubkey", svc.AppsShowHandler, nodeMiddleware)
e.DELETE("/api/apps/:pubkey", svc.AppsDeleteHandler, nodeMiddleware)
e.POST("/api/apps", svc.AppsCreateHandler, nodeMiddleware)

e.GET("/api/csrf", svc.CSRFHandler)
e.GET("/api/info", svc.InfoHandler)
Expand Down

0 comments on commit 84a1a5c

Please sign in to comment.