From 4114121aed2c2eb04b0e3e71b0758e868df6847f Mon Sep 17 00:00:00 2001 From: abdout Date: Sat, 25 Apr 2026 12:49:15 +0300 Subject: [PATCH] fix(ts): rename User.username refs to User.name (Class 2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Prisma schema defines User.name (no username field). Seven call sites still referenced the removed username, masked by typescript.ignoreBuildErrors. The real bug: src/auth.ts:122 set token.name = existingUser.username, which is undefined at runtime, so every JWT token shipped a name=undefined. session.user.name has been undefined for every signed-in user. Files renamed or updated: - src/auth.ts (JWT enrichment — actual bug fix) - src/components/marketing/pricing/forms/user-name.action.ts - src/components/marketing/pricing/actions/update-user-name.ts - src/components/marketing/pricing/lib/user.ts - src/components/marketing/pricing/lib/email.ts - src/components/marketing/pricing/shared/user-avatar.tsx - src/components/marketing/pricing/modals/delete-account-modal.tsx (cascade — UserAvatar caller updated) Skipped: lib/get-tier-id.ts (db.subscriptionTier — separate Class 1 schema issue, deferred). Closes #17 Co-Authored-By: Claude Opus 4.7 (1M context) --- src/auth.ts | 2 +- src/components/marketing/pricing/actions/update-user-name.ts | 2 +- src/components/marketing/pricing/forms/user-name.action.ts | 2 +- src/components/marketing/pricing/lib/email.ts | 2 +- src/components/marketing/pricing/lib/user.ts | 2 +- .../marketing/pricing/modals/delete-account-modal.tsx | 2 +- src/components/marketing/pricing/shared/user-avatar.tsx | 4 ++-- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/auth.ts b/src/auth.ts index de539a0..567ac2f 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -119,7 +119,7 @@ export const { const existingAccount = await getAccountByUserId(existingUser.id) token.isOAuth = !!existingAccount - token.name = existingUser.username + token.name = existingUser.name token.email = existingUser.email token.role = existingUser.role token.isTwoFactorEnabled = existingUser.isTwoFactorEnabled diff --git a/src/components/marketing/pricing/actions/update-user-name.ts b/src/components/marketing/pricing/actions/update-user-name.ts index c3f1bc5..b9f24fb 100644 --- a/src/components/marketing/pricing/actions/update-user-name.ts +++ b/src/components/marketing/pricing/actions/update-user-name.ts @@ -25,7 +25,7 @@ export async function updateUserName(userId: string, data: FormData) { id: userId, }, data: { - username: name, + name: name, }, }) diff --git a/src/components/marketing/pricing/forms/user-name.action.ts b/src/components/marketing/pricing/forms/user-name.action.ts index 5cfc16e..871bfc5 100644 --- a/src/components/marketing/pricing/forms/user-name.action.ts +++ b/src/components/marketing/pricing/forms/user-name.action.ts @@ -12,7 +12,7 @@ export async function updateUserName(userId: string, data: FormData) { if (!parsed.success) { return { status: "error" as const }; } - await db.user.update({ where: { id: userId }, data: { username: parsed.data.name } }); + await db.user.update({ where: { id: userId }, data: { name: parsed.data.name } }); revalidatePath("/dashboard/settings"); return { status: "success" as const }; } diff --git a/src/components/marketing/pricing/lib/email.ts b/src/components/marketing/pricing/lib/email.ts index f7102a4..79298ec 100644 --- a/src/components/marketing/pricing/lib/email.ts +++ b/src/components/marketing/pricing/lib/email.ts @@ -28,7 +28,7 @@ export const sendVerificationRequest: EmailConfig["sendVerificationRequest"] = : identifier, subject: authSubject, react: MagicLinkEmail({ - firstName: (user.username ?? "") as string, + firstName: (user.name ?? "") as string, actionUrl: url, mailType: userVerified ? "login" : "register", siteName: siteConfig.name, diff --git a/src/components/marketing/pricing/lib/user.ts b/src/components/marketing/pricing/lib/user.ts index bcea88c..cb9b341 100644 --- a/src/components/marketing/pricing/lib/user.ts +++ b/src/components/marketing/pricing/lib/user.ts @@ -7,7 +7,7 @@ export const getUserByEmail = async (email: string) => { email: email, }, select: { - username: true, + name: true, emailVerified: true, }, }); diff --git a/src/components/marketing/pricing/modals/delete-account-modal.tsx b/src/components/marketing/pricing/modals/delete-account-modal.tsx index 2f6358e..ce0c940 100644 --- a/src/components/marketing/pricing/modals/delete-account-modal.tsx +++ b/src/components/marketing/pricing/modals/delete-account-modal.tsx @@ -49,7 +49,7 @@ function DeleteAccountModal({
diff --git a/src/components/marketing/pricing/shared/user-avatar.tsx b/src/components/marketing/pricing/shared/user-avatar.tsx index 666581a..5048a5b 100644 --- a/src/components/marketing/pricing/shared/user-avatar.tsx +++ b/src/components/marketing/pricing/shared/user-avatar.tsx @@ -5,7 +5,7 @@ import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar" import { Icons } from "@/components/marketing/pricing/shared/icons" interface UserAvatarProps extends AvatarProps { - user: Pick + user: Pick } export function UserAvatar({ user, ...props }: UserAvatarProps) { @@ -15,7 +15,7 @@ export function UserAvatar({ user, ...props }: UserAvatarProps) { ) : ( - {user.username ?? ""} + {user.name ?? ""} )}