Files
weeklyreport/backend/api/auth/login-history.get.ts
2026-01-04 20:58:47 +09:00

38 lines
824 B
TypeScript

import { query } from '../../utils/db'
/**
* 본인 로그인 이력 조회
* GET /api/auth/login-history
*/
export default defineEventHandler(async (event) => {
const userId = getCookie(event, 'user_id')
if (!userId) {
throw createError({ statusCode: 401, message: '로그인이 필요합니다.' })
}
const history = await query<any>(`
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
}))
}
})