// /components/auth/authController.js const catchAsync = require('../../utils/catchAsync'); const authService = require('./authService'); const { successResponse } = require('../../utils/apiResponse'); exports.login = catchAsync(async (req, res, next) => { const { username, password } = req.body; const result = await authService.login(username, password); return successResponse(res, 200, 'Login successful', result); }); exports.refresh = catchAsync(async (req, res, next) => { const { refreshToken } = req.body; const result = await authService.refreshToken(refreshToken); return successResponse(res, 200, 'Tokens refreshed successfully', result); }); exports.logout = catchAsync(async (req, res, next) => { const { refreshToken } = req.body; const userId = req.user?._id; await authService.logout(userId, refreshToken); return successResponse(res, 200, 'Logout successful'); }); exports.changePassword = catchAsync(async (req, res) => { const { currentPassword, newPassword, refreshToken } = req.body; await authService.changePassword(req.user._id, { currentPassword, newPassword, refreshToken }); return successResponse(res, 200, 'Password changed successfully'); });