migrate organizations from clerk to in-house
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
import { randomUUID } from 'crypto';
|
||||
import { clerkClient } from '@clerk/fastify';
|
||||
import type { z } from 'zod';
|
||||
|
||||
import { hashPassword, slug, stripTrailingSlash } from '@openpanel/common';
|
||||
import { db, getId } from '@openpanel/db';
|
||||
import { db, getId, getOrganizationBySlug } from '@openpanel/db';
|
||||
import type { ProjectType } from '@openpanel/db';
|
||||
import { zOnboardingProject } from '@openpanel/validation';
|
||||
|
||||
@@ -14,16 +13,16 @@ async function createOrGetOrganization(
|
||||
userId: string
|
||||
) {
|
||||
if (input.organizationSlug) {
|
||||
return await clerkClient.organizations.getOrganization({
|
||||
slug: input.organizationSlug,
|
||||
});
|
||||
return await getOrganizationBySlug(input.organizationSlug);
|
||||
}
|
||||
|
||||
if (input.organization) {
|
||||
return await clerkClient.organizations.createOrganization({
|
||||
name: input.organization,
|
||||
slug: slug(input.organization),
|
||||
createdBy: userId,
|
||||
return db.organization.create({
|
||||
data: {
|
||||
id: slug(input.organization),
|
||||
name: input.organization,
|
||||
createdByUserId: userId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -44,7 +43,7 @@ export const onboardingRouter = createTRPCRouter({
|
||||
ctx.session.userId
|
||||
);
|
||||
|
||||
if (!organization?.slug) {
|
||||
if (!organization?.id) {
|
||||
throw new Error('Organization slug is missing');
|
||||
}
|
||||
|
||||
@@ -52,7 +51,7 @@ export const onboardingRouter = createTRPCRouter({
|
||||
data: {
|
||||
id: await getId('project', input.project),
|
||||
name: input.project,
|
||||
organizationSlug: organization.slug,
|
||||
organizationSlug: organization.id,
|
||||
types,
|
||||
},
|
||||
});
|
||||
@@ -61,7 +60,7 @@ export const onboardingRouter = createTRPCRouter({
|
||||
const client = await db.client.create({
|
||||
data: {
|
||||
name: `${project.name} Client`,
|
||||
organizationSlug: organization.slug,
|
||||
organizationSlug: organization.id,
|
||||
projectId: project.id,
|
||||
type: 'write',
|
||||
cors: input.domain ? stripTrailingSlash(input.domain) : null,
|
||||
|
||||
Reference in New Issue
Block a user