refactor(sso): update trusted origins handling and introduce license …#3736
refactor(sso): update trusted origins handling and introduce license …#3736Siumauricio merged 5 commits intocanaryfrom
Conversation
…validation - Replaced user data fetching with a dedicated query for trusted origins in SSO settings. - Updated mutation functions to utilize the new trusted origins query. - Introduced a new service function to validate enterprise licenses based on organization ownership. - Enhanced SSO router to ensure trusted origins are managed by the organization owner. - Added callback URL for email sign-in in the home page.
- Eliminated the getTrustedOrigins query from the user router to streamline the API and improve code maintainability.
| const hasValidLicenseResult = await hasValidLicense( | ||
| ctx.session.activeOrganizationId, | ||
| ); |
There was a problem hiding this comment.
Two additional DB queries on every enterprise procedure call
hasValidLicense() performs two DB queries (organization lookup + user lookup) and is now called in the middleware for every enterpriseProcedure request. Previously, this check used ctx.user properties that were already loaded during context creation.
This means every SSO operation (list providers, get trusted origins, add/remove/update origins, register/update/delete providers) now incurs two extra DB round-trips. Consider caching the license validation result on the context during createTRPCContext or using a short-lived in-memory cache to avoid redundant lookups on every request.
Additional Comments (1)
This query does not include Additionally, the This endpoint appears unused after this PR (the frontend was refactored to use |
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
…r ID retrieval - Removed the unused import of the organization schema. - Introduced a new import for the getOrganizationOwnerId function to enhance license validation logic.
What is this PR about?
Please describe in a short paragraph what this PR is about.
Checklist
Before submitting this PR, please make sure that:
canarybranch.Issues related (if applicable)
Screenshots (if applicable)
Greptile Summary
This PR refactors SSO trusted origins handling and enterprise license validation to be organization-aware rather than user-specific. The key changes are:
enterpriseProcedureandhaveValidLicenseKeynow look up the organization owner's license status instead of checking the calling user'sctx.userproperties. A newhasValidLicense()service function encapsulates this logic.add,remove,update,getTrustedOrigins) now resolve the organization owner and read/write theirtrustedOriginsfield, instead of usingctx.session.userId.api.sso.getTrustedOrigins(a new dedicated endpoint) instead of fetching trusted origins fromapi.user.get.callbackURL: "/dashboard/projects"was added to the email sign-in call.Issues found:
user.getTrustedOriginsendpoint inuser.tsis broken — it queries members withoutwith: { user: true }, so it always returns[]. It also doesn't filter by user. This endpoint appears to be dead code after the frontend refactoring but should be removed or fixed.enterpriseProcedurenow makes 2 DB queries (organization + user lookup) on every request, where it previously used pre-loaded context properties.hasValidLicenseandgetOrganizationOwnerIdboth implement the same organization owner lookup.Confidence Score: 3/5
apps/dokploy/server/api/routers/user.ts(broken getTrustedOrigins endpoint) andapps/dokploy/server/api/trpc.ts(performance regression in enterpriseProcedure middleware).Last reviewed commit: 4e8d37b