Skip to content

Commit dc8ff78

Browse files
authored
Merge pull request #3931 from Dokploy/3928-foreign-key-constraint-violation-on-git_provider-during-github-setup-userid-is-empty---v0284
refactor: replace authClient with api.user.session.useQuery in multip…
2 parents 95e14b4 + 735c995 commit dc8ff78

File tree

6 files changed

+29
-14
lines changed

6 files changed

+29
-14
lines changed

apps/dokploy/components/dashboard/search-command.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import {
2323
CommandList,
2424
CommandSeparator,
2525
} from "@/components/ui/command";
26-
import { authClient } from "@/lib/auth-client";
2726
import { api } from "@/utils/api";
2827
import { StatusTooltip } from "../shared/status-tooltip";
2928

@@ -56,7 +55,7 @@ export const SearchCommand = () => {
5655
const router = useRouter();
5756
const [open, setOpen] = React.useState(false);
5857
const [search, setSearch] = React.useState("");
59-
const { data: session } = authClient.useSession();
58+
const { data: session } = api.user.session.useQuery();
6059
const { data } = api.project.all.useQuery(undefined, {
6160
enabled: !!session,
6261
});

apps/dokploy/components/dashboard/settings/git/github/add-github-provider.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ import {
1212
} from "@/components/ui/dialog";
1313
import { Input } from "@/components/ui/input";
1414
import { Switch } from "@/components/ui/switch";
15-
import { authClient } from "@/lib/auth-client";
1615
import { api } from "@/utils/api";
1716

1817
export const AddGithubProvider = () => {
1918
const [isOpen, setIsOpen] = useState(false);
2019
const { data: activeOrganization } = api.organization.active.useQuery();
2120

22-
const { data: session } = authClient.useSession();
21+
const { data: session } = api.user.session.useQuery();
2322
const { data } = api.user.get.useQuery();
2423
const [manifest, setManifest] = useState("");
2524
const [isOrganization, setIsOrganization] = useState(false);
@@ -99,8 +98,8 @@ export const AddGithubProvider = () => {
9998
<form
10099
action={
101100
isOrganization
102-
? `https://github.com/organizations/${organizationName}/settings/apps/new?state=gh_init:${activeOrganization?.id}`
103-
: `https://github.com/settings/apps/new?state=gh_init:${activeOrganization?.id}`
101+
? `https://github.com/organizations/${organizationName}/settings/apps/new?state=gh_init:${activeOrganization?.id}:${session?.user?.id ?? ""}`
102+
: `https://github.com/settings/apps/new?state=gh_init:${activeOrganization?.id}:${session?.user?.id ?? ""}`
104103
}
105104
method="post"
106105
>

apps/dokploy/components/dashboard/settings/users/show-users.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const ShowUsers = () => {
3737
const { mutateAsync } = api.user.remove.useMutation();
3838

3939
const utils = api.useUtils();
40-
const { data: session } = authClient.useSession();
40+
const { data: session } = api.user.session.useQuery();
4141

4242
return (
4343
<div className="w-full">

apps/dokploy/components/layouts/side.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ function SidebarLogo() {
546546
const { state } = useSidebar();
547547
const { data: isCloud } = api.settings.isCloud.useQuery();
548548
const { data: user } = api.user.get.useQuery();
549-
const { data: session } = authClient.useSession();
549+
const { data: session } = api.user.session.useQuery();
550550
const {
551551
data: organizations,
552552
refetch,

apps/dokploy/pages/api/providers/github/setup.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,29 @@ type Query = {
1010
state: string;
1111
installation_id: string;
1212
setup_action: string;
13-
userId: string;
1413
};
1514

1615
export default async function handler(
1716
req: NextApiRequest,
1817
res: NextApiResponse,
1918
) {
20-
const { code, state, installation_id, userId }: Query = req.query as Query;
19+
const { code, state, installation_id }: Query = req.query as Query;
2120

2221
if (!code) {
2322
return res.status(400).json({ error: "Missing code parameter" });
2423
}
25-
const [action, value] = state?.split(":");
26-
// Value could be the organizationId or the githubProviderId
24+
const [action, ...rest] = state?.split(":");
25+
// For gh_init: rest[0] = organizationId, rest[1] = userId
26+
// For gh_setup: rest[0] = githubProviderId
2727

2828
if (action === "gh_init") {
29+
const organizationId = rest[0];
30+
const userId = rest[1] || (req.query.userId as string);
31+
32+
if (!userId) {
33+
return res.status(400).json({ error: "Missing userId parameter" });
34+
}
35+
2936
const octokit = new Octokit({});
3037
const { data } = await octokit.request(
3138
"POST /app-manifests/{code}/conversions",
@@ -44,7 +51,7 @@ export default async function handler(
4451
githubWebhookSecret: data.webhook_secret,
4552
githubPrivateKey: data.pem,
4653
},
47-
value as string,
54+
organizationId as string,
4855
userId,
4956
);
5057
} else if (action === "gh_setup") {
@@ -53,7 +60,7 @@ export default async function handler(
5360
.set({
5461
githubInstallationId: installation_id,
5562
})
56-
.where(eq(github.githubId, value as string))
63+
.where(eq(github.githubId, rest[0] as string))
5764
.returning();
5865
}
5966

apps/dokploy/server/api/routers/user.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@ export const userRouter = createTRPCRouter({
101101

102102
return memberResult;
103103
}),
104+
session: protectedProcedure.query(async ({ ctx }) => {
105+
return {
106+
user: {
107+
id: ctx.user.id,
108+
},
109+
session: {
110+
activeOrganizationId: ctx.session.activeOrganizationId,
111+
},
112+
};
113+
}),
104114
get: protectedProcedure.query(async ({ ctx }) => {
105115
const memberResult = await db.query.member.findFirst({
106116
where: and(

0 commit comments

Comments
 (0)