Skip to content

refactor: replace authClient with api.user.session.useQuery in multip…#3931

Merged
Siumauricio merged 3 commits intocanaryfrom
3928-foreign-key-constraint-violation-on-git_provider-during-github-setup-userid-is-empty---v0284
Mar 8, 2026
Merged

refactor: replace authClient with api.user.session.useQuery in multip…#3931
Siumauricio merged 3 commits intocanaryfrom
3928-foreign-key-constraint-violation-on-git_provider-during-github-setup-userid-is-empty---v0284

Conversation

@Siumauricio
Copy link
Contributor

@Siumauricio Siumauricio commented Mar 8, 2026

…le components for improved session management

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:

  • You created a dedicated branch based on the canary branch.
  • You have read the suggestions in the CONTRIBUTING.md file https://github.com/Dokploy/dokploy/blob/canary/CONTRIBUTING.md#pull-request
  • You have tested this PR in your local instance. If you have not tested it yet, please do so before submitting. This helps avoid wasting maintainers' time reviewing code that has not been verified by you.

Issues related (if applicable)

closes #3928

Screenshots (if applicable)

Greptile Summary

This PR refactors multiple components to replace authClient.useSession() with a new tRPC endpoint api.user.session.useQuery() for session management, and fixes the GitHub App setup flow by embedding the userId in the OAuth state parameter instead of relying on a separate query param.

Key changes:

  • Adds a new session tRPC protectedProcedure in user.ts that returns only user.id and session.activeOrganizationId
  • Replaces authClient.useSession() in search-command.tsx, add-github-provider.tsx, show-users.tsx, and side.tsx
  • Updates add-github-provider.tsx to encode userId inside the GitHub state string (gh_init:{orgId}:{userId})
  • Updates setup.ts to parse the userId out of the state string with a backward-compatible fallback

Issues found:

  • Critical: authClient import was removed from show-users.tsx, but authClient.organization.removeMember() is still called in the Unlink User handler — this will throw a ReferenceError at runtime
  • Logic: In add-github-provider.tsx, the session?.user?.id ?? "" fallback can embed an empty string as the userId in the state URL when the session query hasn't resolved yet, causing a 400 Missing userId parameter error in setup.ts if the form is submitted too early

Confidence Score: 1/5

  • Not safe to merge — there is a broken import that will cause a runtime error in production.
  • The removal of the authClient import from show-users.tsx while leaving authClient.organization.removeMember() in use is a definite runtime ReferenceError. Any admin or owner who attempts to unlink a user from the organization will hit a crash. This is a functional regression that needs to be resolved before merging.
  • apps/dokploy/components/dashboard/settings/users/show-users.tsx requires immediate attention due to the missing authClient import.

Comments Outside Diff (1)

  1. apps/dokploy/components/dashboard/settings/users/show-users.tsx, line 260-264 (link)

    authClient removed but still referenced

    The import import { authClient } from "@/lib/auth-client" was removed from this file in this PR, but authClient.organization.removeMember(...) is still called here. This will throw a ReferenceError: authClient is not defined at runtime whenever a user is unlinked.

    The import needs to be restored, or the call needs to be migrated to an equivalent tRPC mutation.

    To fix, restore the import:

    import { authClient } from "@/lib/auth-client";

Last reviewed commit: 2182129

Greptile also left 1 inline comment on this PR.

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. enhancement New feature or request labels Mar 8, 2026
Comment on lines +101 to 103
? `https://github.com/organizations/${organizationName}/settings/apps/new?state=gh_init:${activeOrganization?.id}:${session?.user?.id ?? ""}`
: `https://github.com/settings/apps/new?state=gh_init:${activeOrganization?.id}:${session?.user?.id ?? ""}`
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty string userId when session is still loading

When api.user.session.useQuery() hasn't resolved yet, session is undefined, so session?.user?.id ?? "" evaluates to "". This embeds an empty string as the userId segment in the GitHub state parameter (e.g., gh_init:{orgId}:).

In setup.ts, the handler extracts const userId = rest[1] || (req.query.userId as string). When rest[1] is "" (falsy), it falls back to req.query.userId, which GitHub does not supply — resulting in a 400 Missing userId parameter error if the form is submitted before the session query resolves.

The submit button should be disabled until both the session and the active organization are available:

Suggested change
? `https://github.com/organizations/${organizationName}/settings/apps/new?state=gh_init:${activeOrganization?.id}:${session?.user?.id ?? ""}`
: `https://github.com/settings/apps/new?state=gh_init:${activeOrganization?.id}:${session?.user?.id ?? ""}`
}
<Button
disabled={(isOrganization && organizationName.length < 1) || !session?.user?.id || !activeOrganization?.id}
type="submit"
className="self-end"
>
Create GitHub App
</Button>

@Siumauricio Siumauricio merged commit dc8ff78 into canary Mar 8, 2026
4 checks passed
@Siumauricio Siumauricio deleted the 3928-foreign-key-constraint-violation-on-git_provider-during-github-setup-userid-is-empty---v0284 branch March 8, 2026 00:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Foreign key constraint violation on git_provider during GitHub setup (userId is empty) - v0.28.4

1 participant