From a8467e80e86b9b69917c4dac62d3af0e32737ca2 Mon Sep 17 00:00:00 2001 From: Mauricio Siu Date: Sat, 7 Mar 2026 18:02:25 -0600 Subject: [PATCH 1/3] refactor: replace authClient with api.user.session.useQuery in multiple components for improved session management --- .../components/dashboard/search-command.tsx | 3 +-- .../git/github/add-github-provider.tsx | 8 ++++---- .../dashboard/settings/users/show-users.tsx | 3 +-- apps/dokploy/components/layouts/side.tsx | 2 +- .../pages/api/providers/github/setup.ts | 19 +++++++++++++------ apps/dokploy/server/api/routers/user.ts | 10 ++++++++++ 6 files changed, 30 insertions(+), 15 deletions(-) diff --git a/apps/dokploy/components/dashboard/search-command.tsx b/apps/dokploy/components/dashboard/search-command.tsx index bbd612d92..b98099b5f 100644 --- a/apps/dokploy/components/dashboard/search-command.tsx +++ b/apps/dokploy/components/dashboard/search-command.tsx @@ -23,7 +23,6 @@ import { CommandList, CommandSeparator, } from "@/components/ui/command"; -import { authClient } from "@/lib/auth-client"; import { api } from "@/utils/api"; import { StatusTooltip } from "../shared/status-tooltip"; @@ -56,7 +55,7 @@ export const SearchCommand = () => { const router = useRouter(); const [open, setOpen] = React.useState(false); const [search, setSearch] = React.useState(""); - const { data: session } = authClient.useSession(); + const { data: session } = api.user.session.useQuery(); const { data } = api.project.all.useQuery(undefined, { enabled: !!session, }); diff --git a/apps/dokploy/components/dashboard/settings/git/github/add-github-provider.tsx b/apps/dokploy/components/dashboard/settings/git/github/add-github-provider.tsx index d29b3a345..60fe2d343 100644 --- a/apps/dokploy/components/dashboard/settings/git/github/add-github-provider.tsx +++ b/apps/dokploy/components/dashboard/settings/git/github/add-github-provider.tsx @@ -12,14 +12,14 @@ import { } from "@/components/ui/dialog"; import { Input } from "@/components/ui/input"; import { Switch } from "@/components/ui/switch"; -import { authClient } from "@/lib/auth-client"; import { api } from "@/utils/api"; export const AddGithubProvider = () => { const [isOpen, setIsOpen] = useState(false); const { data: activeOrganization } = api.organization.active.useQuery(); - const { data: session } = authClient.useSession(); + const { data: session } = api.user.session.useQuery(); + console.log(session); const { data } = api.user.get.useQuery(); const [manifest, setManifest] = useState(""); const [isOrganization, setIsOrganization] = useState(false); @@ -99,8 +99,8 @@ export const AddGithubProvider = () => {
diff --git a/apps/dokploy/components/dashboard/settings/users/show-users.tsx b/apps/dokploy/components/dashboard/settings/users/show-users.tsx index 0245739f8..56f029664 100644 --- a/apps/dokploy/components/dashboard/settings/users/show-users.tsx +++ b/apps/dokploy/components/dashboard/settings/users/show-users.tsx @@ -26,7 +26,6 @@ import { TableHeader, TableRow, } from "@/components/ui/table"; -import { authClient } from "@/lib/auth-client"; import { api } from "@/utils/api"; import { AddUserPermissions } from "./add-permissions"; import { ChangeRole } from "./change-role"; @@ -37,7 +36,7 @@ export const ShowUsers = () => { const { mutateAsync } = api.user.remove.useMutation(); const utils = api.useUtils(); - const { data: session } = authClient.useSession(); + const { data: session } = api.user.session.useQuery(); return (
diff --git a/apps/dokploy/components/layouts/side.tsx b/apps/dokploy/components/layouts/side.tsx index f34c33a31..6dea37f5b 100644 --- a/apps/dokploy/components/layouts/side.tsx +++ b/apps/dokploy/components/layouts/side.tsx @@ -546,7 +546,7 @@ function SidebarLogo() { const { state } = useSidebar(); const { data: isCloud } = api.settings.isCloud.useQuery(); const { data: user } = api.user.get.useQuery(); - const { data: session } = authClient.useSession(); + const { data: session } = api.user.session.useQuery(); const { data: organizations, refetch, diff --git a/apps/dokploy/pages/api/providers/github/setup.ts b/apps/dokploy/pages/api/providers/github/setup.ts index c09d6fba5..663939c5e 100644 --- a/apps/dokploy/pages/api/providers/github/setup.ts +++ b/apps/dokploy/pages/api/providers/github/setup.ts @@ -10,22 +10,29 @@ type Query = { state: string; installation_id: string; setup_action: string; - userId: string; }; export default async function handler( req: NextApiRequest, res: NextApiResponse, ) { - const { code, state, installation_id, userId }: Query = req.query as Query; + const { code, state, installation_id }: Query = req.query as Query; if (!code) { return res.status(400).json({ error: "Missing code parameter" }); } - const [action, value] = state?.split(":"); - // Value could be the organizationId or the githubProviderId + const [action, ...rest] = state?.split(":"); + // For gh_init: rest[0] = organizationId, rest[1] = userId + // For gh_setup: rest[0] = githubProviderId if (action === "gh_init") { + const organizationId = rest[0]; + const userId = rest[1] || (req.query.userId as string); + + if (!userId) { + return res.status(400).json({ error: "Missing userId parameter" }); + } + const octokit = new Octokit({}); const { data } = await octokit.request( "POST /app-manifests/{code}/conversions", @@ -44,7 +51,7 @@ export default async function handler( githubWebhookSecret: data.webhook_secret, githubPrivateKey: data.pem, }, - value as string, + organizationId as string, userId, ); } else if (action === "gh_setup") { @@ -53,7 +60,7 @@ export default async function handler( .set({ githubInstallationId: installation_id, }) - .where(eq(github.githubId, value as string)) + .where(eq(github.githubId, rest[0] as string)) .returning(); } diff --git a/apps/dokploy/server/api/routers/user.ts b/apps/dokploy/server/api/routers/user.ts index 3f217ceed..f67b62925 100644 --- a/apps/dokploy/server/api/routers/user.ts +++ b/apps/dokploy/server/api/routers/user.ts @@ -101,6 +101,16 @@ export const userRouter = createTRPCRouter({ return memberResult; }), + session: protectedProcedure.query(async ({ ctx }) => { + return { + user: { + id: ctx.user.id, + }, + session: { + activeOrganizationId: ctx.session.activeOrganizationId, + }, + }; + }), get: protectedProcedure.query(async ({ ctx }) => { const memberResult = await db.query.member.findFirst({ where: and( From 21821295e3d7f17b7d97567b78dfbc27dcc6a8d3 Mon Sep 17 00:00:00 2001 From: Mauricio Siu Date: Sat, 7 Mar 2026 18:10:35 -0600 Subject: [PATCH 2/3] chore: remove console.log for session in AddGithubProvider component to clean up code --- .../dashboard/settings/git/github/add-github-provider.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/dokploy/components/dashboard/settings/git/github/add-github-provider.tsx b/apps/dokploy/components/dashboard/settings/git/github/add-github-provider.tsx index 60fe2d343..f2ba167ff 100644 --- a/apps/dokploy/components/dashboard/settings/git/github/add-github-provider.tsx +++ b/apps/dokploy/components/dashboard/settings/git/github/add-github-provider.tsx @@ -19,7 +19,6 @@ export const AddGithubProvider = () => { const { data: activeOrganization } = api.organization.active.useQuery(); const { data: session } = api.user.session.useQuery(); - console.log(session); const { data } = api.user.get.useQuery(); const [manifest, setManifest] = useState(""); const [isOrganization, setIsOrganization] = useState(false); From 735c9952d8bca5b357ad033d091e7698c54c6eae Mon Sep 17 00:00:00 2001 From: Mauricio Siu Date: Sat, 7 Mar 2026 18:14:30 -0600 Subject: [PATCH 3/3] chore: import authClient in show-users component for enhanced authentication handling --- apps/dokploy/components/dashboard/settings/users/show-users.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/dokploy/components/dashboard/settings/users/show-users.tsx b/apps/dokploy/components/dashboard/settings/users/show-users.tsx index 56f029664..f4bc9b897 100644 --- a/apps/dokploy/components/dashboard/settings/users/show-users.tsx +++ b/apps/dokploy/components/dashboard/settings/users/show-users.tsx @@ -26,6 +26,7 @@ import { TableHeader, TableRow, } from "@/components/ui/table"; +import { authClient } from "@/lib/auth-client"; import { api } from "@/utils/api"; import { AddUserPermissions } from "./add-permissions"; import { ChangeRole } from "./change-role";