기능구현중
This commit is contained in:
33
server/api/auth/logout.post.ts
Normal file
33
server/api/auth/logout.post.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { getClientIp } from '../../utils/ip'
|
||||
import { getDbSession, deleteSession, getSessionIdFromCookie, deleteSessionCookie } from '../../utils/session'
|
||||
|
||||
/**
|
||||
* 로그아웃
|
||||
* POST /api/auth/logout
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
const sessionId = getSessionIdFromCookie(event)
|
||||
const clientIp = getClientIp(event)
|
||||
|
||||
if (sessionId) {
|
||||
// 세션 정보 조회
|
||||
const session = await getDbSession(sessionId)
|
||||
|
||||
// 로그아웃 이력 기록
|
||||
if (session?.loginHistoryId) {
|
||||
await execute(`
|
||||
UPDATE wr_login_history
|
||||
SET logout_at = NOW(), logout_ip = $1
|
||||
WHERE history_id = $2
|
||||
`, [clientIp, session.loginHistoryId])
|
||||
}
|
||||
|
||||
// DB에서 세션 삭제
|
||||
await deleteSession(sessionId)
|
||||
}
|
||||
|
||||
// 세션 쿠키 삭제
|
||||
deleteSessionCookie(event)
|
||||
|
||||
return { success: true }
|
||||
})
|
||||
Reference in New Issue
Block a user