Reflex/backend/routes/authRoutes.js

44 lines
2.5 KiB
JavaScript
Raw 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');
const { checkDeviceBlock, recordDeviceActivity } = require('../middleware/deviceBlockMiddleware');
// --- НАЧАЛО ИЗМЕНЕНИЯ ---
// Дополнительная отладка: Проверяем, что 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);
console.log('[DEBUG] authRoutes.js - typeof checkDeviceBlock:', typeof checkDeviceBlock);
// Регистрация пользователя - с проверкой блокировки устройства
router.post('/register', checkDeviceBlock, registerUser);
// Вход пользователя - с проверкой блокировки устройства и записью активности
router.post('/login', checkDeviceBlock, loginUser, recordDeviceActivity);
// Получение профиля - защищенный доступ с записью активности устройства
router.get('/me', protect, recordDeviceActivity, getMe);
// Экспортируем маршруты
module.exports = router;
// Конец файла