MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / createClient

Function createClient

apps/api/src/controllers/manage.controller.ts:294–335  ·  view source on GitHub ↗
(
  request: FastifyRequest<{ Body: z.infer<typeof zCreateClient> }>,
  reply: FastifyReply
)

Source from the content-addressed store, hash-verified

292}
293
294export async function createClient(
295 request: FastifyRequest<{ Body: z.infer<typeof zCreateClient> }>,
296 reply: FastifyReply
297) {
298 const { name, projectId, type } = request.body;
299
300 // If projectId is provided, verify it belongs to organization
301 if (projectId) {
302 const project = await db.project.findFirst({
303 where: {
304 id: projectId,
305 organizationId: request.client!.organizationId,
306 },
307 });
308
309 if (!project) {
310 throw new HttpError('Project not found', { status: 404 });
311 }
312 }
313
314 // Generate secret
315 const secret = `sec_${crypto.randomBytes(10).toString('hex')}`;
316
317 const client = await db.client.create({
318 data: {
319 organizationId: request.client!.organizationId,
320 projectId: projectId || null,
321 name,
322 type: type || 'write',
323 secret: await hashPassword(secret),
324 },
325 });
326
327 await getClientByIdCached.clear(client.id);
328
329 reply.send({
330 data: {
331 ...client,
332 secret, // Return plain secret only once
333 },
334 });
335}
336
337export async function updateClient(
338 request: FastifyRequest<{

Callers 5

client.tsFile · 0.85
migration.tsFile · 0.85
getChatClientFunction · 0.85
getClientFunction · 0.85
getClientFunction · 0.85

Calls 4

hashPasswordFunction · 0.90
toStringMethod · 0.45
clearMethod · 0.45
sendMethod · 0.45

Tested by

no test coverage detected