import { getSession, refreshSession, getSessionIdFromCookie, deleteSessionCookie } from '../../utils/session' /** * 현재 로그인 사용자 정보 * GET /api/auth/current-user */ export default defineEventHandler(async (event) => { const sessionId = getSessionIdFromCookie(event) if (!sessionId) { return { user: null } } // DB에서 세션 조회 const session = await getSession(sessionId) if (!session) { // 세션이 만료되었거나 없음 → 쿠키 삭제 deleteSessionCookie(event) return { user: null } } // 사용자 정보 조회 const employee = await queryOne(` SELECT * FROM wr_employee_info WHERE employee_id = $1 AND is_active = true `, [session.employeeId]) if (!employee) { deleteSessionCookie(event) return { user: null } } // 세션 갱신 (Sliding Expiration - 10분 연장) await refreshSession(sessionId) // 로그인 이력의 last_active_at도 업데이트 if (session.loginHistoryId) { await execute(` UPDATE wr_login_history SET last_active_at = NOW() WHERE history_id = $1 `, [session.loginHistoryId]) } return { user: { employeeId: employee.employee_id, employeeName: employee.employee_name, employeeEmail: employee.employee_email, employeePosition: employee.employee_position } } })