Skip to content

fix(account): correct principal operator name key and guard against m… - #973

Open
rcjasub wants to merge 1 commit into
mainfrom
fix/account-db-principal-name-null-guard
Open

fix(account): correct principal operator name key and guard against m…#973
rcjasub wants to merge 1 commit into
mainfrom
fix/account-db-principal-name-null-guard

Conversation

@rcjasub

@rcjasub rcjasub commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Title: fix(account): correct principal operator name key and guard against missing farm record (#971)

Summary

  • Fixed a key mismatch in getAccountUsersData() where principalContact was returning name but users/page.tsx was reading firstName, causing the Principal Operator name to always render blank on /account/users
  • Added a null guard in getAccountFarmData() to throw a descriptive error if no farm record is found, preventing a silent TypeError crash on /account

Changes

apps/site/src/app/(authenticated)/(shell)/(accounts)/account/db.ts

  • Renamed name → firstName in principalContact to match what users/page.tsx expects and to be consistent with how the owner object is shaped
  • Added if (!farmRecord) check before accessing .farm and .farm_location on the destructured query result

Root Cause

Both bugs were isolated to db.ts:

  1. The principalContact object was built with a name key but the page consumed it as firstName. TypeScript didn't catch this because the return type is Partial, which allows all fields to be undefined — so accessing a missing key silently returned undefined instead of throwing.
  2. Drizzle's destructured query result (const [farmRecord] = await db...) returns undefined if no rows match. Without a guard, accessing farmRecord.farm would throw a TypeError if a user's farm record is missing from the DB.

Testing

  • Navigate to /account/users — Principal Operator name should now display correctly
  • Verify /account loads without errors for authenticated users

Closes #971

@vercel

vercel Bot commented Jun 30, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
internal-dashboard Ready Ready Preview, Comment Jun 30, 2026 12:41am
nightcrawler Ready Ready Preview, Comment Jun 30, 2026 12:41am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: db/loading issue in Vercel test environment for /account pages

1 participant