Skip to content

Improve room mapping FK diagnostics and cleanup#58

Merged
SaltProphet merged 1 commit intomainfrom
view-sql-error-for-room-creation
Mar 5, 2026
Merged

Improve room mapping FK diagnostics and cleanup#58
SaltProphet merged 1 commit intomainfrom
view-sql-error-for-room-creation

Conversation

@SaltProphet
Copy link
Owner

Motivation

  • Users creating rooms saw opaque foreign-key failures (rooms_user_id_fkey) after Daily.co room creation, leaving orphaned Daily rooms and insufficient diagnostic info to debug the database issue.
  • The change aims to surface actionable SQL diagnostics and avoid leaving Daily.co rooms when local persistence fails.

Description

  • Add a service-role preflight check using createServerSupabaseServiceClient() and auth.admin.getUserById to verify the session user exists in auth.users before attempting DB writes in createStaticRoom.
  • Introduce formatSupabaseError to include message, code, details, and hint in returned DB error strings so FK failures are actionable.
  • Add deleteDailyRoom that issues a DELETE to Daily.co to clean up a just-created room when the DB insert fails, and invoke it on insert error.
  • Update unit tests in src/app/actions/createStaticRoom.test.ts to mock the service client and add a test verifying SQL diagnostics are included and the Daily.co cleanup DELETE is called on failure.

Testing

  • Ran the unit tests with npm test -- src/app/actions/createStaticRoom.test.ts.
  • All tests in that file passed: 6 passed, 6 total.

Codex Task

@vercel
Copy link
Contributor

vercel bot commented Mar 5, 2026

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

Project Deployment Actions Updated (UTC)
secpriva Ready Ready Preview, Comment Mar 5, 2026 3:59pm

Request Review

@SaltProphet SaltProphet merged commit 451339d into main Mar 5, 2026
3 of 9 checks passed
@SaltProphet SaltProphet deleted the view-sql-error-for-room-creation branch March 5, 2026 16:00
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 612f3643f3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

const serviceClient = createServerSupabaseServiceClient()
if (serviceClient) {
const { data: authUser, error: authUserError } = await serviceClient.auth.admin.getUserById(userId)
if (authUserError || !authUser?.user) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Distinguish admin lookup failures from missing auth users

This branch treats any auth.admin.getUserById error the same as a confirmed missing user, so transient Auth API failures (or a temporary service-role misconfiguration) will reject room creation for valid logged-in users with the misleading message that the account does not exist. Because this check now runs before all writes, a control-plane hiccup can block the entire flow even when the session and DB insert path would otherwise work; only the !authUser?.user case should trigger the “missing account” response.

Useful? React with 👍 / 👎.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant