Improve room mapping FK diagnostics and cleanup#58
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
💡 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) { |
There was a problem hiding this comment.
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 👍 / 👎.
Motivation
rooms_user_id_fkey) after Daily.co room creation, leaving orphaned Daily rooms and insufficient diagnostic info to debug the database issue.Description
createServerSupabaseServiceClient()andauth.admin.getUserByIdto verify the session user exists inauth.usersbefore attempting DB writes increateStaticRoom.formatSupabaseErrorto includemessage,code,details, andhintin returned DB error strings so FK failures are actionable.deleteDailyRoomthat issues aDELETEto Daily.co to clean up a just-created room when the DB insert fails, and invoke it on insert error.src/app/actions/createStaticRoom.test.tsto mock the service client and add a test verifying SQL diagnostics are included and the Daily.co cleanupDELETEis called on failure.Testing
npm test -- src/app/actions/createStaticRoom.test.ts.6 passed, 6 total.Codex Task