import { query } from '../../utils/db' /** * 본인 로그인 이력 조회 * GET /api/auth/login-history */ export default defineEventHandler(async (event) => { const userId = getCookie(event, 'user_id') const currentHistoryId = getCookie(event, 'login_history_id') if (!userId) { throw createError({ statusCode: 401, message: '로그인이 필요합니다.' }) } const history = await query(` SELECT history_id, login_at, login_ip, logout_at, logout_ip, last_active_at FROM wr_login_history WHERE employee_id = $1 ORDER BY login_at DESC LIMIT 50 `, [userId]) return { history: history.map(h => ({ historyId: h.history_id, loginAt: h.login_at, loginIp: h.login_ip, logoutAt: h.logout_at, logoutIp: h.logout_ip, lastActiveAt: h.last_active_at, isCurrentSession: currentHistoryId && h.history_id === parseInt(currentHistoryId) })) } })