Skip to content

feat(examples): organization multi-tenancy in react-neon-js - #149

Open
Shridhad wants to merge 3 commits into
mainfrom
feat/examples/react-neon-js-organizations
Open

feat(examples): organization multi-tenancy in react-neon-js#149
Shridhad wants to merge 3 commits into
mainfrom
feat/examples/react-neon-js-organizations

Conversation

@Shridhad

Copy link
Copy Markdown
Collaborator

Summary

  • Extend examples/react-neon-js with Neon Auth Organizations plugin: OrganizationSwitcher, /organization/:pathname routes, and organization={{}} on NeonAuthUIProvider.
  • Add RLS for team todos scoped to JWT claim o (public.jwt_organization() ->> 'id') plus personal todos (organization_id IS NULL).
  • Ship incremental SQL migrations (migration-organization.sql, migration-personal-todos.sql) for existing databases.
  • Update E2E to create personal todos without requiring an active org first.

Test plan

  • Enable Organizations plugin on Neon Auth endpoint used by the example
  • Apply migration.sql (new DB) or migration-organization.sql + migration-personal-todos.sql (existing)
  • Sign in → create personal todo without org → create org → add team todo → switch org
  • Verify anonymous users still see public todos only
  • Run pnpm run build and E2E against example (pnpm run --filter e2e test:ci) when credentials available

Demonstrate Neon Auth JWT claim `o` for org-scoped RLS alongside personal
todos, with auth-ui OrganizationSwitcher and organization management routes.
@vercel

vercel Bot commented May 22, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
neon-auth-nextjs Ready Ready Preview, Comment May 28, 2026 8:02pm

Request Review

philip added 2 commits May 27, 2026 14:22
- Add SECURITY DEFINER to jwt_organization() in all three migration files;
  without it authenticated role gets permission denied on auth schema
- Fix invalid DROP FUNCTION ... ->> 'id' syntax in incremental migrations
- Add /account/organizations view to AccountPage; OrganizationView
  unconditionally redirects there when no active org, leaving a dead page
- Replace hooks.useActiveMember() with activeOrg.members lookup;
  useActiveMember is not on the exported AuthHooks type, causing TS build failure

Co-authored-by: Isaac
After switching active organization the JWT with the stale `o` claim
remained cached for up to 15 minutes (full JWT TTL), causing every
team-scoped Data API request to 403 until expiry.

Intercept /organization/set-active and call invalidateSessionCache()
on success, consistent with the existing signOut pattern.

Co-authored-by: Isaac
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.

2 participants