make onboarding + create client easier
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import { randomUUID } from 'crypto';
|
||||
import { createTRPCRouter, protectedProcedure } from '@/server/api/trpc';
|
||||
import { db } from '@/server/db';
|
||||
import { hashPassword } from '@openpanel/common';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { hashPassword } from '@openpanel/common';
|
||||
|
||||
export const clientRouter = createTRPCRouter({
|
||||
list: protectedProcedure
|
||||
.input(
|
||||
@@ -59,7 +60,7 @@ export const clientRouter = createTRPCRouter({
|
||||
name: z.string(),
|
||||
projectId: z.string(),
|
||||
organizationId: z.string(),
|
||||
withCors: z.boolean().default(true),
|
||||
cors: z.string().nullable(),
|
||||
})
|
||||
)
|
||||
.mutation(async ({ input }) => {
|
||||
@@ -69,41 +70,14 @@ export const clientRouter = createTRPCRouter({
|
||||
organization_slug: input.organizationId,
|
||||
project_id: input.projectId,
|
||||
name: input.name,
|
||||
secret: input.withCors ? null : await hashPassword(secret),
|
||||
secret: input.cors ? null : await hashPassword(secret),
|
||||
cors: input.cors || undefined,
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
clientSecret: input.withCors ? null : secret,
|
||||
clientId: client.id,
|
||||
cors: client.cors,
|
||||
};
|
||||
}),
|
||||
create2: protectedProcedure
|
||||
.input(
|
||||
z.object({
|
||||
name: z.string(),
|
||||
projectId: z.string(),
|
||||
organizationId: z.string(),
|
||||
domain: z.string().nullish(),
|
||||
})
|
||||
)
|
||||
.mutation(async ({ input }) => {
|
||||
const secret = randomUUID();
|
||||
const client = await db.client.create({
|
||||
data: {
|
||||
organization_slug: input.organizationId,
|
||||
project_id: input.projectId,
|
||||
name: input.name,
|
||||
secret: input.domain ? undefined : await hashPassword(secret),
|
||||
cors: input.domain || undefined,
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
clientSecret: input.domain ? null : secret,
|
||||
clientId: client.id,
|
||||
cors: client.cors,
|
||||
...client,
|
||||
secret: input.cors ? null : secret,
|
||||
};
|
||||
}),
|
||||
remove: protectedProcedure
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
import { randomUUID } from 'crypto';
|
||||
import { createTRPCRouter, protectedProcedure } from '@/server/api/trpc';
|
||||
import { clerkClient } from '@clerk/nextjs';
|
||||
import { db } from '@openpanel/db';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { hashPassword } from '@openpanel/common';
|
||||
import { db } from '@openpanel/db';
|
||||
|
||||
export const onboardingRouter = createTRPCRouter({
|
||||
organziation: protectedProcedure
|
||||
.input(
|
||||
z.object({
|
||||
organization: z.string(),
|
||||
project: z.string().optional(),
|
||||
project: z.string(),
|
||||
cors: z.string().nullable(),
|
||||
})
|
||||
)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
@@ -17,7 +21,7 @@ export const onboardingRouter = createTRPCRouter({
|
||||
createdBy: ctx.session.userId,
|
||||
});
|
||||
|
||||
if (org.slug && input.project) {
|
||||
if (org.slug) {
|
||||
const project = await db.project.create({
|
||||
data: {
|
||||
name: input.project,
|
||||
@@ -25,13 +29,29 @@ export const onboardingRouter = createTRPCRouter({
|
||||
},
|
||||
});
|
||||
|
||||
const secret = randomUUID();
|
||||
const client = await db.client.create({
|
||||
data: {
|
||||
name: `${project.name} Client`,
|
||||
organization_slug: org.slug,
|
||||
project_id: project.id,
|
||||
cors: input.cors ?? '*',
|
||||
secret: input.cors ? null : await hashPassword(secret),
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
client: {
|
||||
...client,
|
||||
secret,
|
||||
},
|
||||
project,
|
||||
organization: org,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
client: null,
|
||||
project: null,
|
||||
organization: org,
|
||||
};
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
import { createTRPCRouter, protectedProcedure } from '@/server/api/trpc';
|
||||
import {
|
||||
createTRPCRouter,
|
||||
protectedProcedure,
|
||||
publicProcedure,
|
||||
} from '@/server/api/trpc';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { db, getReferences } from '@openpanel/db';
|
||||
import { zCreateReference, zRange } from '@openpanel/validation';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { getChartStartEndDate } from './chart.helpers';
|
||||
|
||||
@@ -29,7 +34,7 @@ export const referenceRouter = createTRPCRouter({
|
||||
},
|
||||
});
|
||||
}),
|
||||
getChartReferences: protectedProcedure
|
||||
getChartReferences: publicProcedure
|
||||
.input(
|
||||
z.object({
|
||||
projectId: z.string(),
|
||||
|
||||
Reference in New Issue
Block a user