Files
harheimertc/server/api/cms/users/reject.post.js
Torsten Schulz (local) 3586704cce
Some checks failed
Code Analysis and Production Deploy / analyze (push) Failing after 10m29s
Code Analysis and Production Deploy / deploy-production (push) Has been skipped
Code Analysis and Production Deploy / deploy-test (push) Has been skipped
Update file permissions for multiple server and test files to executable mode
2026-07-15 08:45:12 +02:00

39 lines
1002 B
JavaScript
Executable File

import { getUserFromToken, readUsers, writeUsers, hasAnyRole } from '../../../utils/auth.js'
import { writeAuditLog } from '../../../utils/audit-log.js'
export default defineEventHandler(async (event) => {
try {
const token = getCookie(event, 'auth_token')
const currentUser = await getUserFromToken(token)
if (!currentUser || !hasAnyRole(currentUser, 'admin')) {
throw createError({
statusCode: 403,
message: 'Zugriff verweigert'
})
}
const body = await readBody(event)
const { userId } = body
const users = await readUsers()
const updatedUsers = users.filter(u => u.id !== userId)
await writeUsers(updatedUsers)
await writeAuditLog('cms.user.rejected', {
actorUserId: currentUser.id,
targetUserId: userId
})
return {
success: true,
message: 'Registrierung wurde abgelehnt und gelöscht'
}
} catch (error) {
console.error('Fehler beim Ablehnen:', error)
throw error
}
})