import { d as defineEventHandler, g as getCookie, c as createError } from '../../nitro/nitro.mjs';
import { b as verifyToken, e as getUserById } 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 profile_get = defineEventHandler(async (event) => {
  try {
    const token = getCookie(event, "auth_token");
    if (!token) {
      throw createError({
        statusCode: 401,
        message: "Nicht authentifiziert."
      });
    }
    const decoded = verifyToken(token);
    if (!decoded) {
      throw createError({
        statusCode: 401,
        message: "Ung\xFCltiges Token."
      });
    }
    const user = await getUserById(decoded.id);
    if (!user || user.active === false) {
      throw createError({
        statusCode: 403,
        message: "Benutzer nicht gefunden oder inaktiv."
      });
    }
    return {
      success: true,
      user: {
        id: user.id,
        email: user.email,
        name: user.name,
        phone: user.phone || "",
        role: user.role
      }
    };
  } catch (error) {
    console.error("Profil-Abruf-Fehler:", error);
    throw error;
  }
});

export { profile_get as default };
//# sourceMappingURL=profile.get.mjs.map
