fix onboarding

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-06-16 23:12:22 +02:00
parent 4f9c624d08
commit fd7fb16313
2 changed files with 15 additions and 6 deletions

View File

@@ -2,7 +2,7 @@ import { randomUUID } from 'crypto';
import type { z } from 'zod'; import type { z } from 'zod';
import { hashPassword, slug, stripTrailingSlash } from '@openpanel/common'; import { hashPassword, slug, stripTrailingSlash } from '@openpanel/common';
import { db, getId, getOrganizationBySlug } from '@openpanel/db'; import { db, getId, getOrganizationBySlug, getUserById } from '@openpanel/db';
import type { ProjectType } from '@openpanel/db'; import type { ProjectType } from '@openpanel/db';
import { zOnboardingProject } from '@openpanel/validation'; import { zOnboardingProject } from '@openpanel/validation';
@@ -38,15 +38,24 @@ export const onboardingRouter = createTRPCRouter({
if (input.app) types.push('app'); if (input.app) types.push('app');
if (input.backend) types.push('backend'); if (input.backend) types.push('backend');
const organization = await createOrGetOrganization( const [organization, user] = await Promise.all([
input, createOrGetOrganization(input, ctx.session.userId),
ctx.session.userId getUserById(ctx.session.userId),
); ]);
if (!organization?.id) { if (!organization?.id) {
throw new Error('Organization slug is missing'); throw new Error('Organization slug is missing');
} }
await db.member.create({
data: {
email: user.email,
organizationId: organization.id,
role: 'org:admin',
userId: user.id,
},
});
const project = await db.project.create({ const project = await db.project.create({
data: { data: {
id: await getId('project', input.project), id: await getId('project', input.project),

View File

@@ -2,7 +2,7 @@ import { clerkClient } from '@clerk/fastify';
import { pathOr } from 'ramda'; import { pathOr } from 'ramda';
import { z } from 'zod'; import { z } from 'zod';
import { db, getOrganizationBySlug } from '@openpanel/db'; import { db } from '@openpanel/db';
import { zInviteUser } from '@openpanel/validation'; import { zInviteUser } from '@openpanel/validation';
import { createTRPCRouter, protectedProcedure } from '../trpc'; import { createTRPCRouter, protectedProcedure } from '../trpc';