Skip to content

Keep production tenant context for Google and availability - #1

Open
damian123 wants to merge 1 commit into
nateherkai:mainfrom
damian123:fix/production-tenant-context
Open

damian123 wants to merge 1 commit into
nateherkai:mainfrom
damian123:fix/production-tenant-context

Conversation

@damian123

@damian123 damian123 commented Aug 29, 2026 •

Copy link
Copy Markdown

Summary

Production Postgres RLS hid workspace rows after Next.js dropped AsyncLocalStorage across await. That made a live Google Calendar connection look unavailable and caused availability saves to fail when updating the organizer timezone.

  • Rebind signed tenant context with runWithDatabaseContext / reconstructed enterDatabaseAction scope on Google status, OAuth token persist, availability, onboarding, and related writes.
  • Persist Google token refreshes under oauth_write, and update user timezone under account_write after the availability schedule write.
  • Copy the Prisma query engine into the standalone web path so production signup/readiness can load.
  • Log Prisma P#### codes on unhandled API errors without leaking tokens.

Verified on book.XXX.xyz: Integrations reports Google connected with complete calendar access, and PUT /api/availability returns 200.

Test plan

  • Sign in on a production-path Postgres deploy and confirm Integrations shows Google Connected / full calendar access without reconnecting.
  • Save weekly hours on /availability and confirm Availability saved.
  • Complete onboarding if a new workspace is created.
  • vitest run apps/web/src/server/db-context.test.ts apps/web/src/server/services/availability.test.ts apps/web/src/server/services/calendar.test.ts

Postgres RLS dropped workspace context after Next.js awaits, so Google
looked disconnected and availability saves failed. Rebind signed tenant
context across those writes and persist Google token refreshes under
oauth_write.
@damian123

Copy link
Copy Markdown
Author

Rebased check: this branch is already one commit ahead of current main (no additional rebase needed).

Local verification just re-ran and passed:

vitest run apps/web/src/server/db-context.test.ts \
  apps/web/src/server/services/availability.test.ts \
  apps/web/src/server/services/calendar.test.ts

39 passed / 0 failed.

Ready for review when you have time.

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.

1 participant