From 1cb7437d855a7b0e8fe26a99ef60496e9c8b9598 Mon Sep 17 00:00:00 2001 From: Andrea Timaran Date: Tue, 19 Apr 2022 02:38:44 -0500 Subject: [PATCH 1/4] Default userName after singup --- apps/web/pages/api/user/[id].ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/apps/web/pages/api/user/[id].ts b/apps/web/pages/api/user/[id].ts index 252f9279b2345f..236838434f569d 100644 --- a/apps/web/pages/api/user/[id].ts +++ b/apps/web/pages/api/user/[id].ts @@ -4,6 +4,9 @@ import type { NextApiRequest, NextApiResponse } from "next"; import { getSession } from "@lib/auth"; import prisma from "@lib/prisma"; +import slugify from "@lib/slugify"; +import { randomString } from "@lib/random"; + export default async function handler(req: NextApiRequest, res: NextApiResponse) { const session = await getSession({ req }); @@ -33,6 +36,28 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) } if (req.method === "PATCH") { + const user = await prisma.user.findFirst({ + where: { + id: authenticatedUser.id, + }, + select: { + username: true, + name: true, + }, + }); + + if(!user?.username && user?.name && req.body.data?.completedOnboarding){ + const usernameSlug = (username: string) => slugify(username) + "-" + randomString(6).toLowerCase(); + const firstUserName = usernameSlug(user.name); + await prisma.user.update({ + where: { + id: authenticatedUser.id, + }, + data: { + username: firstUserName, + }, + }); + } const updatedUser = await prisma.user.update({ where: { id: authenticatedUser.id, From c868311bbe07ea20f7e8441e35c4d555b480be2b Mon Sep 17 00:00:00 2001 From: andreaestefania12 <19562383+andreaestefania12@users.noreply.github.com> Date: Tue, 19 Apr 2022 09:18:08 -0500 Subject: [PATCH 2/4] Update apps/web/pages/api/user/[id].ts Co-authored-by: Miguel Nieto A <39246879+miguelnietoa@users.noreply.github.com> --- apps/web/pages/api/user/[id].ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/web/pages/api/user/[id].ts b/apps/web/pages/api/user/[id].ts index 236838434f569d..2b36ef3905da90 100644 --- a/apps/web/pages/api/user/[id].ts +++ b/apps/web/pages/api/user/[id].ts @@ -3,9 +3,8 @@ import type { NextApiRequest, NextApiResponse } from "next"; import { getSession } from "@lib/auth"; import prisma from "@lib/prisma"; - -import slugify from "@lib/slugify"; import { randomString } from "@lib/random"; +import slugify from "@lib/slugify"; export default async function handler(req: NextApiRequest, res: NextApiResponse) { const session = await getSession({ req }); From 3abc21ecb183d54a32ceeb7b8a59291e648e0633 Mon Sep 17 00:00:00 2001 From: andreaestefania12 <19562383+andreaestefania12@users.noreply.github.com> Date: Tue, 19 Apr 2022 09:18:32 -0500 Subject: [PATCH 3/4] Update apps/web/pages/api/user/[id].ts Co-authored-by: Miguel Nieto A <39246879+miguelnietoa@users.noreply.github.com> --- apps/web/pages/api/user/[id].ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/web/pages/api/user/[id].ts b/apps/web/pages/api/user/[id].ts index 2b36ef3905da90..bce12d59a9ae74 100644 --- a/apps/web/pages/api/user/[id].ts +++ b/apps/web/pages/api/user/[id].ts @@ -45,9 +45,9 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) }, }); - if(!user?.username && user?.name && req.body.data?.completedOnboarding){ + if (!user?.username && user?.name && req.body.data?.completedOnboarding) { const usernameSlug = (username: string) => slugify(username) + "-" + randomString(6).toLowerCase(); - const firstUserName = usernameSlug(user.name); + const firstUserName = usernameSlug(user.name); await prisma.user.update({ where: { id: authenticatedUser.id, From a312e285664fb963d3a10f2ca551b4ecca32621e Mon Sep 17 00:00:00 2001 From: Andrea Timaran Date: Tue, 19 Apr 2022 09:21:56 -0500 Subject: [PATCH 4/4] Update apps/web/pages/api/user/[id].ts --- apps/web/pages/api/user/[id].ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/web/pages/api/user/[id].ts b/apps/web/pages/api/user/[id].ts index bce12d59a9ae74..420ecbe28ea5fc 100644 --- a/apps/web/pages/api/user/[id].ts +++ b/apps/web/pages/api/user/[id].ts @@ -35,7 +35,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) } if (req.method === "PATCH") { - const user = await prisma.user.findFirst({ + const user = await prisma.user.findUnique({ where: { id: authenticatedUser.id, },