fix(api): restore default org roles in Better Auth access control#35
Open
natori-hrj wants to merge 1 commit into
Open
fix(api): restore default org roles in Better Auth access control#35natori-hrj wants to merge 1 commit into
natori-hrj wants to merge 1 commit into
Conversation
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.
Problem
A self-hosted instance cannot invite anyone. On a fresh install, the owner of the auto-created workspace gets:
The UI shows a failed toast and no invitation row is written.
Cause
Better Auth 1.5.4 resolves the organization role table as:
options.roles || defaultRolesis evaluated before the spread, so supplyingrolesREPLACES the plugin's defaults rather than extending them.apps/api/src/lib/auth.tsregisters onlyrestricted:That comment's premise does not hold —
owner,adminandmemberend up with no statements at all, so everyhasPermissioncheck denies them.Blast radius — lines matching
hasPermissionin the org plugin's routes:Fix
Spread
defaultRolesback in sorestrictedis genuinely a fourth role, and replace the comment with one that documents the replace-not-extend behaviour.Verification
Self-hosted mode (
CLOUD_MODE=false) on Postgres, built withdocker compose up -d --build. The same image was rebuilt from the parent commit to measure the "before" column, so both columns are observed rather than inferred. Each row isPOST /api/auth/organization/invite-memberby the sole workspace member, with that member's role set to the value in column 1:owneradminmemberrestrictedAfter the fix,
ownerandadminwrite aninvitationrow (status = pending), andlist-members/list-invitationsreturn 200 for the owner.memberandrestrictedstill answer{"error":"Forbidden"}— that ismiddleware/better-auth-shield.tsrejecting them before the plugin runs, not the plugin's ownYOU_ARE_NOT_ALLOWED_…. So the shield's role policy is unchanged by this patch, andrestrictedkeeps zero plugin-side permissions.bun install --frozen-lockfileandbun run --cwd apps/api lint(the CI typecheck) both pass.Notes
No test is included. The two tests that reference
lib/auth(github.auth.test.ts,github.controller.test.ts)vi.mockit rather than loading the real module — it buildsbetterAuth()at module scope with the DB adapter — so there is no existing pattern inapps/api/testfor exercising this config. Happy to add a test if you'd like a particular shape.