import { getTokenFromRequest, verifyJwtToken } from './chunk-OCR5DS4C.mjs';

// src/auth/server.ts
async function validateApiAuth(request) {
  try {
    const token = getTokenFromRequest(request);
    if (!token) return null;
    const secret = process.env.JWT_SECRET || "your-secret-key";
    const payload = await verifyJwtToken(token, secret);
    if (!payload || !payload.userId) return null;
    return {
      id: payload.userId,
      email: payload.email,
      username: payload.username,
      role: payload.role
    };
  } catch (error) {
    console.error("API \u8EAB\u4EFD\u9A8C\u8BC1\u5931\u8D25:", error);
    return null;
  }
}
async function validateApiAuthNumeric(request) {
  const user2 = await validateApiAuth(request);
  if (!user2) return null;
  return {
    ...user2,
    id: parseInt(user2.id, 10)
  };
}

export { validateApiAuth, validateApiAuthNumeric };
//# sourceMappingURL=chunk-6BZ3QFA5.mjs.map
//# sourceMappingURL=chunk-6BZ3QFA5.mjs.map