modified: main_dc/yalarba/api_yal/go.mod
modified: main_dc/yalarba/api_yal/go.sum modified: main_dc/yalarba/api_yal/internal/domain/auth/dto.go modified: main_dc/yalarba/api_yal/internal/domain/auth/handler.go modified: main_dc/yalarba/api_yal/internal/domain/auth/router.go modified: main_dc/yalarba/api_yal/internal/domain/auth/servcie.go new file: main_dc/yalarba/api_yal/internal/middleware/auth.go deleted: main_dc/yalarba/api_yal/internal/middleware/authMiddleware.go modified: main_dc/yalarba/api_yal/internal/router/router.go set auth domain, not tested
This commit is contained in:
@@ -3,33 +3,39 @@ package auth
|
||||
import (
|
||||
"api_yal/internal/logger"
|
||||
"api_yal/internal/middleware"
|
||||
"api_yal/internal/repository"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// RegisterRoutes регистрирует маршруты аутентификации
|
||||
func RegisterRoutes(r chi.Router) {
|
||||
handler := NewAuthHandler(NewAuthService())
|
||||
func RegisterRoutes(r chi.Router, db *gorm.DB, jwtSecret string) {
|
||||
// Создаем репозиторий и сервис
|
||||
accountRepo := repository.NewAccountRepository(db)
|
||||
authService := NewAuthService(accountRepo, jwtSecret)
|
||||
handler := NewAuthHandler(&authService)
|
||||
|
||||
l := logger.Get()
|
||||
l.Debug("Регистрация маршрутов аутентификации")
|
||||
|
||||
r.Route("/auth", func(r chi.Router) {
|
||||
// Публичные маршруты (без аутентификации)
|
||||
r.Group(func(r chi.Router) {
|
||||
// r.Post("/login", handler.Login)
|
||||
r.Post("/login", handler.Login)
|
||||
r.Post("/register", handler.Register)
|
||||
// r.Post("/refresh", handler.RefreshToken)
|
||||
r.Post("/refresh", handler.RefreshToken)
|
||||
// r.Post("/reset-password", handler.ResetPassword)
|
||||
})
|
||||
|
||||
// Защищенные маршруты (требуют аутентификации)
|
||||
r.Group(func(r chi.Router) {
|
||||
r.Use(middleware.AuthMiddlewareWithContext) // middleware специфичный для auth
|
||||
r.Use(middleware.AuthMiddleware(jwtSecret))
|
||||
|
||||
// r.Post("/logout", handler.Logout)
|
||||
// r.Get("/profile", handler.GetProfile)
|
||||
// r.Put("/profile", handler.UpdateProfile)
|
||||
// r.Post("/change-password", handler.ChangePassword)
|
||||
r.Post("/logout", handler.Logout)
|
||||
r.Get("/profile", handler.GetProfile)
|
||||
r.Put("/profile", handler.UpdateProfile)
|
||||
r.Post("/change-password", handler.ChangePassword)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user