27 lines
761 B
TypeScript
27 lines
761 B
TypeScript
import { NextRequest, NextResponse } from 'next/server'
|
|
import { getCurrentUser } from '@/lib/auth'
|
|
import { writeAuditLog, getClientIP } from '@/lib/audit'
|
|
|
|
export async function POST(request: NextRequest) {
|
|
// 先获取当前用户信息(用于审计日志),再清除 cookie
|
|
const user = await getCurrentUser()
|
|
|
|
const r = NextResponse.json({ success: true })
|
|
|
|
if (user) {
|
|
writeAuditLog({
|
|
userId: user.id,
|
|
apiKeyId: null,
|
|
action: 'logout',
|
|
entityType: 'auth',
|
|
entityId: user.id,
|
|
details: { username: user.username },
|
|
ipAddress: getClientIP(request),
|
|
})
|
|
}
|
|
|
|
r.cookies.set('session_issue', '', { maxAge: 0, path: '/' })
|
|
r.cookies.set('tlyq_session', '', { maxAge: 0, path: '/' })
|
|
return r
|
|
}
|