feat: auth middleware
This commit is contained in:
@ -7,6 +7,8 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"gitea.local/admin/hspguard/internal/auth"
|
||||
imiddleware "gitea.local/admin/hspguard/internal/middleware"
|
||||
"gitea.local/admin/hspguard/internal/repository"
|
||||
"gitea.local/admin/hspguard/internal/user"
|
||||
"github.com/go-chi/chi/v5"
|
||||
@ -34,8 +36,13 @@ func (s *APIServer) Run() error {
|
||||
FileServer(router, "/static", staticDir)
|
||||
|
||||
router.Route("/api/v1", func(r chi.Router) {
|
||||
r.Use(imiddleware.WithSkipper(imiddleware.AuthMiddleware, "/api/v1/login", "/api/v1/register"))
|
||||
|
||||
userHandler := user.NewUserHandler(s.repo)
|
||||
userHandler.RegisterRoutes(router, r)
|
||||
|
||||
authHandler := auth.NewAuthHandler(s.repo)
|
||||
authHandler.RegisterRoutes(router, r)
|
||||
})
|
||||
|
||||
// Handle unknown routes
|
||||
@ -48,7 +55,7 @@ func (s *APIServer) Run() error {
|
||||
router.MethodNotAllowed(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||
fmt.Fprint(w, `{"error": "405 - method not allowed"}`)
|
||||
_, _ = fmt.Fprint(w, `{"error": "405 - method not allowed"}`)
|
||||
})
|
||||
|
||||
log.Println("Listening on", s.addr)
|
||||
|
Reference in New Issue
Block a user