Files
tp/main_dc/yalarba/api_yal/internal/domain/auth/router.go
T
valitovgaziz d45c5841dc 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
2026-03-10 00:35:25 +05:00

41 lines
1.3 KiB
Go

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, 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("/register", handler.Register)
r.Post("/refresh", handler.RefreshToken)
// r.Post("/reset-password", handler.ResetPassword)
})
// Защищенные маршруты (требуют аутентификации)
r.Group(func(r chi.Router) {
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)
})
})
}