Repository navigation
Move (app) pages and server actions onto the principal [ABD-21] - #725
Merged
Merged
Conversation
Pages read their user from the gate instead of looking the session up
again with getAuthUser / getRequestUserWithMfa, and drop the signed-out
branches the gate already redirects. app-page-gate.test.ts accepts
const { user } = await requireCompletedSignup() as the first statement.
authedAction runs the action in a viewer frame for the cookie user (2FA and completed signup enforced) and returns the action's unauthorized result otherwise. Settings and admin actions use it; checks that span users (username or email taken) and deleting the account row move to the system connection, since the restricted role sees and updates only its own row. authed-action.test.ts requires the wrapper on every (app) action.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Fourth step of ABD-21 (one request principal). #720–#722 put every API route behind
authedRoute; this does the same for(app)pages and server actions.requireCompletedSignup()returns the principal. Pages writeconst { user } = await requireCompletedSignup();instead of looking the session up again withgetAuthUser/getRequestUserWithMfa(dashboard, rooms, save, settings tokens/import/export/invites), and drop the signed-out branches the gate already redirects.app-page-gate.test.tsaccepts that form as the first statement, with a test that a principal declared after a query still fails.authedAction(@/lib/auth/authed-action), the server-action counterpart ofauthedRoute: runs the action in a viewer frame for the cookie user (2FA and completed signup enforced) and returns the action's own unauthorized result without running it. Server actions previously never ran in a viewer frame, so RLS never applied to them.changeUsername,deleteAccount,requestEmailChange(settings) anddeleteUserAsAdmin,reprocessIssueGroupAsAdmin(admin, admin check kept inside).usersrow, so the username/email-taken checks read onsystemReadand deleting the account row usessystemDb.settings/actions.tsis added to thesystemDballowlist inbiome.json.changeUsernamewrites only columns granted toabode_app.authed-action.test.tscovers the wrapper and fails for any(app)action exported another way (only the reviewedsignOutre-export is allowed).AGENTS.md,app/src/app/AGENTS.md) updated.Thread: https://ampcode.com/threads/T-01a1e700-7a74-76b5-85a8-6c3a6faaad6c
Checklist
.env.example, in-app help,CONTRIBUTING.md, onboarding checklist), or N/A — N/A for user docs; agent guidance updated as abovecaptureServerException/ the error boundary, or N/A — N/A, no new error pathsauthed-action.test.ts(wrapper contract + gate),app-page-gate.test.tsextended; existing settings/admin action tests pass through the wrapperrecord-pr-demoskill); refactor through a user flow → parity run, or N/A — N/A, auth plumbing only; E2E covers the flowslearnskill, or N/A — N/A, not a defect fix; the action gate is the new guardrailNotes
Verified locally:
bun run check:fixand lint clean; full unit suite passes (4,470); integration project 659/659 (placeholder Supabase env values).export constand for a plainexport async function(both checked).Not done here:
(auth)actions (login, signup, reset) are pre-sign-in by design and unchanged; admin pages keeprequireAdmin. Remaining ABD-21 steps: an explicitasSystementry point replacing thesystemDballowlist, andRLS_ENFORCEDeverywhere.Summary by cubic
Server actions and
(app)pages now resolve the caller as a single principal instead of looking the session up per file, and(app)server actions get the same gate API routes got.requireCompletedSignup()now returns the principal; pages writeconst { user } = await requireCompletedSignup();and drop the signed-out branches the gate already redirects.authedActionruns each action in a viewer frame with 2FA and completed signup enforced, returning the action'sunauthorizedresult without running it when there's no caller;authed-action.test.tsrequires it on every(app)action except the reviewedsignOutre-export.systemReadand account-row deletion usessystemDb, since the restricted role sees only its own row;settings/actions.tsjoins thesystemDballowlist.Written for commit b632bff. Summary will update on new commits.