import { d as defineEventHandler, g as getCookie, c as createError } from '../../../../nitro/nitro.mjs';
import { a as getUserFromToken, r as readUsers } from '../../../../_/auth.mjs';
import 'node:http';
import 'node:https';
import 'node:events';
import 'node:buffer';
import 'node:fs';
import 'node:path';
import 'node:crypto';
import 'node:url';
import 'bcryptjs';
import 'jsonwebtoken';
import 'fs';
import 'path';
import '../../../../_/encryption.mjs';
import 'crypto';

const list_get = defineEventHandler(async (event) => {
  try {
    const token = getCookie(event, "auth_token");
    const currentUser = await getUserFromToken(token);
    if (!currentUser || currentUser.role !== "admin" && currentUser.role !== "vorstand") {
      throw createError({
        statusCode: 403,
        message: "Zugriff verweigert"
      });
    }
    const users = await readUsers();
    const safeUsers = users.map((u) => ({
      id: u.id,
      email: u.email,
      name: u.name,
      role: u.role,
      phone: u.phone || "",
      active: u.active,
      created: u.created,
      lastLogin: u.lastLogin
    }));
    return {
      users: safeUsers
    };
  } catch (error) {
    console.error("Fehler beim Laden der Benutzer:", error);
    throw error;
  }
});

export { list_get as default };
//# sourceMappingURL=list.get.mjs.map
