Skip to content

docs: add how-to guide for anonymous/pre-account access control - #1012

Merged
borisno2 merged 3 commits into
mainfrom
claude/focused-rubin-pv53ok
Aug 22, 2026
Merged

docs: add how-to guide for anonymous/pre-account access control#1012
borisno2 merged 3 commits into
mainfrom
claude/focused-rubin-pv53ok

Conversation

@borisno2

Copy link
Copy Markdown
Member

Summary

Adds a how-to guide showing the access-scoped pattern for pre-account and anonymous flows — a signed-in-but-not-yet-onboarded session (real session.userId, no owning row yet) — so sudo() + hand-rolled ownership checks stop being the only discoverable option.

Per triage on #966, this is a documentation gap, not a missing mechanism: everything the guide shows already exists in the engine. The page is built around one continuous worked example (AccountProjectTemplate) and establishes:

  • Scope by traversal from session.userId, not a derived session field ({ account: { user: { id: { equals: session.userId } } } } resolves correctly whether or not the owning row exists yet — fail-closed by construction).
  • Deny explicitly when there's no session (session ? {…} : false, never a filter built from a possibly-null session.userId).
  • Force ownership on create in resolveInput, overwriting the owner field from the session rather than validating a client-supplied value.
  • Use validate for what a hook can't force (e.g. a relationship target — an existing Template — that must belong to the caller).
  • context.withSession() substitutes the session without elevating, contrasted explicitly with sudo().
  • When sudo() is still the right call, and what it costs (bypasses operation- and field-level access; every check under it is hand-rolled and fail-open).

Also links the new guide from the Access Control concepts page and registers it in docs navigation (How-to → Build).

No engine or package code changes.

Test plan

  • pnpm link-check (docs) passes — all internal links resolve
  • pnpm build (docs) succeeds and statically generates the new page
  • pnpm format run over the changed files
  • Verified operation-level create access truly has no inputData (only field-level access does) against packages/core/src/access/types.ts, and that returning a filter from create access is currently treated as full allow (write-pipeline.ts) — matches what the guide says not to do

Closes #966


Generated by Claude Code

Documents the access-scoped pattern for pre-account and anonymous flows
(session.userId with no owning row yet) so sudo() + hand-rolled ownership
checks stop being the only discoverable option: scope by traversal from
session.userId, deny explicitly on a null session, force ownership on
create via resolveInput, use validate for choices a hook can't force, and
contrast context.withSession() with sudo().

Closes #966

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016YUoqak9UpdBu1RednLXNy
@changeset-bot

changeset-bot Bot commented Aug 22, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 72e44e5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel

vercel Bot commented Aug 22, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
stack-docs Ready Ready Preview Aug 22, 2026 7:45am

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

Copy link
Copy Markdown

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: 636269ef5e

ℹ️ 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".

Comment thread docs/content/how-to/anonymous-access-control.md Outdated
Comment thread docs/content/how-to/anonymous-access-control.md
@github-actions

github-actions Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Coverage Report for Core Package Coverage (./packages/core)

Status Category Percentage Covered / Total
🟢 Lines 94.04% (🎯 65%) 1626 / 1729
🟢 Statements 92.29% (🎯 65%) 1762 / 1909
🟢 Functions 97.38% (🎯 62%) 261 / 268
🟢 Branches 86.05% (🎯 50%) 1277 / 1484
File CoverageNo changed files found.
Generated in workflow #1778 for commit 72e44e5 by the Vitest Coverage Report Action

@github-actions

github-actions Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Coverage Report for UI Package Coverage (./packages/ui)

Status Category Percentage Covered / Total
🔵 Lines 76.72% 244 / 318
🔵 Statements 76.29% 251 / 329
🔵 Functions 69.15% 74 / 107
🔵 Branches 64.25% 160 / 249
File CoverageNo changed files found.
Generated in workflow #1778 for commit 72e44e5 by the Vitest Coverage Report Action

@github-actions

github-actions Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Coverage Report for CLI Package Coverage (./packages/cli)

Status Category Percentage Covered / Total
🔵 Lines 78.98% 1545 / 1956
🔵 Statements 78.79% 1613 / 2047
🔵 Functions 86.11% 217 / 252
🔵 Branches 69.5% 752 / 1082
File CoverageNo changed files found.
Generated in workflow #1778 for commit 72e44e5 by the Vitest Coverage Report Action

@github-actions

github-actions Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Coverage Report for Auth Package Coverage (./packages/auth)

Status Category Percentage Covered / Total
🔵 Lines 99.36% 157 / 158
🔵 Statements 97.66% 167 / 171
🔵 Functions 100% 40 / 40
🔵 Branches 88.53% 139 / 157
File CoverageNo changed files found.
Generated in workflow #1778 for commit 72e44e5 by the Vitest Coverage Report Action

@github-actions

github-actions Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Coverage Report for Storage Package Coverage (./packages/storage)

Status Category Percentage Covered / Total
🔵 Lines 78.57% 220 / 280
🔵 Statements 80.06% 245 / 306
🔵 Functions 86.07% 68 / 79
🔵 Branches 75.88% 214 / 282
File CoverageNo changed files found.
Generated in workflow #1778 for commit 72e44e5 by the Vitest Coverage Report Action

@github-actions

github-actions Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Coverage Report for RAG Package Coverage (./packages/rag)

Status Category Percentage Covered / Total
🔵 Lines 47.97% 355 / 740
🔵 Statements 48.14% 377 / 783
🔵 Functions 54.26% 70 / 129
🔵 Branches 42.55% 180 / 423
File CoverageNo changed files found.
Generated in workflow #1778 for commit 72e44e5 by the Vitest Coverage Report Action

@github-actions

github-actions Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Coverage Report for Storage S3 Package Coverage (./packages/storage-s3)

Status Category Percentage Covered / Total
🔵 Lines 100% 40 / 40
🔵 Statements 100% 40 / 40
🔵 Functions 100% 9 / 9
🔵 Branches 100% 19 / 19
File CoverageNo changed files found.
Generated in workflow #1778 for commit 72e44e5 by the Vitest Coverage Report Action

@github-actions

github-actions Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Coverage Report for Storage Vercel Package Coverage (./packages/storage-vercel)

Status Category Percentage Covered / Total
🔵 Lines 100% 68 / 68
🔵 Statements 100% 71 / 71
🔵 Functions 100% 15 / 15
🔵 Branches 97.87% 46 / 47
File CoverageNo changed files found.
Generated in workflow #1778 for commit 72e44e5 by the Vitest Coverage Report Action

…guide

The worked example named its business list Account, which collides with
authPlugin()'s own default Account list (the OAuth/credential model) the
moment a reader's config actually uses authPlugin() — the guide's own
premise. Renamed to Workspace and fixed the owner relationship to target
the default auth User list (it referenced a nonexistent AuthUser).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016YUoqak9UpdBu1RednLXNy
@vercel

vercel Bot commented Aug 22, 2026

Copy link
Copy Markdown

Deployment failed for project stack-docs with the following error:

Resource is limited - try again in 24 hours (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/open-saas?upgradeToPro=build-rate-limit

Copy link
Copy Markdown
Member Author

Self-review

Ran a code review pass on this PR before requesting human review. Two correctness findings, both confirmed against the actual codebase and fixed in cea1f8d:

  1. List-naming collision with the auth plugin. The worked example named its business list Account, which collides with authPlugin()'s own default Account list (the OAuth/credential model, packages/auth/src/lists/index.ts) — config load throws Plugin "auth" tried to add list "Account" but it already exists the moment a reader's app calls authPlugin(), which is the guide's own stated premise ("an anonymous Better Auth session mid-signup"). Renamed the business list to Workspace throughout.
  2. Nonexistent AuthUser ref. The example's ownership relationship pointed at ref: 'AuthUser', but the default auth-plugin user list under plain authPlugin() is User (every other doc page in the repo uses ref: 'User.posts' / ref: 'User' for this). Fixed to ref: 'User'.

Re-ran pnpm link-check and pnpm build (docs) after the fix — both pass, and the corrected example is now consistent with the auth plugin's actual default list names.


Generated by Claude Code

Two P1s from Codex review on PR #1012, both real bugs in the worked example:

- The auth User list ships closed by default (ADR-0013), so the nested
  `owner: { connect }` in Workspace.resolveInput would be denied without
  explicit self-only query access on User — every Workspace create in the
  guide would fail as written.
- Template had no query access at all, so the validate hook's scoped
  findFirst lookup would always return null and reject every legitimate
  template selection.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016YUoqak9UpdBu1RednLXNy

Copy link
Copy Markdown
Member Author

Addressed both P1 findings from the Codex review (72e44e5) — replied and resolved both threads.

The Vercel status failure (Deployment rate limited — retry in 24 hours) is the org's free-tier Vercel account hitting its daily preview-deployment cap, not something caused by this PR's content — nothing to fix on my end. The real GitHub Actions checks (test, e2e, GitGuardian) are what actually validate this change; watching those to green.


Generated by Claude Code

@borisno2
borisno2 merged commit c0c9c30 into main Aug 22, 2026
4 of 5 checks passed
@borisno2
borisno2 deleted the claude/focused-rubin-pv53ok branch August 22, 2026 09:22
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.

access: pre-account / anonymous flows have no access-scoped path, forcing sudo() + hand-rolled ownership checks

2 participants