Add orgId parameter to query atoms for multi-tenant support#9
Open
Add orgId parameter to query atoms for multi-tenant support#9
Conversation
The client-side atom cache (Atom.family) keyed query results solely by input parameters (startTime, endTime, etc.) without including the organization context. When an org switch triggered router.invalidate() without a full page reload, cached autocomplete suggestions from org A could be served to org B. Changes: - makeQueryAtomFamily now requires orgId as a second parameter, which is included in the cache key but stripped before passing to the query fn - Created useOrgId() hook using TanStack Router's root route context, works in both Clerk and self-hosted auth modes - Updated all ~35 atom call sites across routes and components to pass orgId, giving compile-time enforcement that no call site can omit it - Applied same fix to widgetDataResultAtom in use-widget-data.ts TypeScript will now error if any new atom call site omits orgId. https://claude.ai/code/session_01JanCyQqgmYrKzHo2yj85ps
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.
Summary
This PR adds organization ID (orgId) as a parameter to all query atom functions throughout the application to support multi-tenant data isolation. The orgId is now extracted from the route context and passed to every data fetching operation.
Key Changes
useOrgId()hook that retrieves the orgId from route context viauseAuth(), providing a centralized way to access the current organization IDmakeQueryAtomFamily()intinybird-query-atoms.tsto accept and encode orgId as part of the cache key, ensuring different organizations' data is cached separatelywidgetDataResultAtom()to include orgId in the cache key for dashboard widget datauseOrgId()calls and passed orgId parameter to all atom value calls across:Implementation Details
_orgIdprefix, which is then stripped during deserialization to maintain backward compatibility with existing input types(input: Input, orgId: string) => Atomhttps://claude.ai/code/session_01JanCyQqgmYrKzHo2yj85ps