diff --git a/apps/webapp/app/models/organization.server.ts b/apps/webapp/app/models/organization.server.ts index 7bcdf45fa..378ac8dbb 100644 --- a/apps/webapp/app/models/organization.server.ts +++ b/apps/webapp/app/models/organization.server.ts @@ -2,20 +2,28 @@ import type { User, Organization } from ".prisma/client"; import { prisma } from "~/db.server"; import slug from "slug"; -export async function createFirstOrganization(userId: string) { +export async function createFirstOrganization(user: User) { + //We want the slug to be based on their name if they have one, otherwise their email + let desiredSlug = user.name ? slug(user.name) : slug(user.email); + return await createOrganization({ title: "Personal Workspace", - userId: userId, + userId: user.id, + desiredSlug, }); } export async function createOrganization({ title, userId, + desiredSlug, }: Pick & { userId: User["id"]; + desiredSlug?: string; }) { - let desiredSlug = slug(title); + if (desiredSlug === undefined) { + desiredSlug = slug(title); + } const withSameSlug = await prisma.organization.findFirst({ where: { slug: desiredSlug }, diff --git a/apps/webapp/app/services/emailAuth.server.tsx b/apps/webapp/app/services/emailAuth.server.tsx index d07f10662..81faa4ca5 100644 --- a/apps/webapp/app/services/emailAuth.server.tsx +++ b/apps/webapp/app/services/emailAuth.server.tsx @@ -64,7 +64,7 @@ const emailStrategy = new EmailLinkStrategy( ); if (isNewUser) { - const firstOrganization = await createFirstOrganization(user.id); + const firstOrganization = await createFirstOrganization(user); await createFirstWorkflow(user.id, firstOrganization.id); await emailProvider.sendWelcomeEmail(user); } diff --git a/apps/webapp/app/services/gitHubAuth.server.ts b/apps/webapp/app/services/gitHubAuth.server.ts index 581956831..9baecbfcb 100644 --- a/apps/webapp/app/services/gitHubAuth.server.ts +++ b/apps/webapp/app/services/gitHubAuth.server.ts @@ -30,7 +30,7 @@ const gitHubStrategy = new GitHubStrategy( }); if (isNewUser) { - const firstOrganization = await createFirstOrganization(user.id); + const firstOrganization = await createFirstOrganization(user); await createFirstWorkflow(user.id, firstOrganization.id); await sendWelcomeEmail(user); }