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..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 @@ -12,14 +12,13 @@ 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(); const { data } = api.user.get.useQuery(); const [manifest, setManifest] = useState(""); const [isOrganization, setIsOrganization] = useState(false); @@ -99,8 +98,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..f4bc9b897 100644 --- a/apps/dokploy/components/dashboard/settings/users/show-users.tsx +++ b/apps/dokploy/components/dashboard/settings/users/show-users.tsx @@ -37,7 +37,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(