Files
tp/main_dc/yalarba/api_yal/internal/domain/auth/router.go
T
valitovgaziz 8b40d1bfe5 On branch main
modified:   internal/domain/auth/dto.go
	modified:   internal/domain/auth/handler.go
	modified:   internal/domain/auth/router.go
	modified:   internal/domain/auth/servcie.go
	modified:   internal/middleware/auth.go
	modified:   internal/router/router.go
auth implemented without reset password
2026-03-31 04:22:54 +05:00

51 lines
1.6 KiB
Go

// router.go
package auth
import (
"api_yal/internal/logger"
"api_yal/internal/middleware"
"api_yal/internal/repository"
"time"
"github.com/go-chi/chi/v5"
"gorm.io/gorm"
)
// RegisterRoutes регистрирует маршруты аутентификации
func RegisterRoutes(r chi.Router, db *gorm.DB, jwtSecret string) {
// Создаем репозиторий и сервис
accountRepo := repository.NewAccountRepository(db)
// Конфигурация токенов
authConfig := AuthServiceConfig{
JWTSecret: jwtSecret,
AccessTokenTTL: 15 * time.Minute, // Access token живет 15 минут
RefreshTokenTTL: 7 * 24 * time.Hour, // Refresh token живет 7 дней
}
authService := NewAuthService(accountRepo, authConfig)
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)
})
})
}