Reflex/backend/routes/authRoutes.js
2025-05-21 22:13:09 +07:00

42 lines
2.0 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Маршруты аутентификации для API
const express = require('express');
const router = express.Router();
// Импортируем функции из контроллера
const {
registerUser,
loginUser,
getMe
} = require('../controllers/authController');
// Импортируем middleware для защиты маршрутов
const { protect } = require('../middleware/authMiddleware');
// --- НАЧАЛО ИЗМЕНЕНИЯ ---
// Дополнительная отладка: Проверяем, что protect действительно функция
console.log('[DEBUG] authRoutes.js - Тип импортированного protect:', typeof protect);
if (typeof protect !== 'function') {
console.error('[КРИТИЧЕСКАЯ ОШИБКА] authRoutes.js - protect middleware НЕ является функцией! Маршрут /me НЕ будет защищен.');
// Можно даже выбросить ошибку, чтобы сервер не стартовал с неработающей аутентификацией
throw new Error('Middleware protect не загружен корректно в authRoutes.js');
}
// --- КОНЕЦ ИЗМЕНЕНИЯ ---
// Отладочные логи для проверки типов импортированных функций
console.log('[DEBUG] authRoutes.js - typeof registerUser:', typeof registerUser);
console.log('[DEBUG] authRoutes.js - typeof loginUser:', typeof loginUser);
console.log('[DEBUG] authRoutes.js - typeof getMe:', typeof getMe);
console.log('[DEBUG] authRoutes.js - typeof protect:', typeof protect);
// Регистрация пользователя - публичный доступ
router.post('/register', registerUser);
// Вход пользователя - публичный доступ
router.post('/login', loginUser);
// Получение профиля - защищенный доступ
router.get('/me', protect, getMe);
// Экспортируем маршруты
module.exports = router;
// Конец файла