refactor: update invitation

This commit is contained in:
Mauricio Siu
2025-02-16 02:57:49 -06:00
parent 4a1a14aeb4
commit e7db0ccb70
29 changed files with 270 additions and 330 deletions

View File

@@ -1,10 +1,12 @@
import { db } from "@/server/db";
import { github } from "@/server/db/schema";
import {
auth,
createGithub,
findAdminByAuthId,
findAuthById,
findUserByAuthId,
findUserById,
} from "@dokploy/server";
import { eq } from "drizzle-orm";
import type { NextApiRequest, NextApiResponse } from "next";
@@ -28,7 +30,7 @@ export default async function handler(
return res.status(400).json({ error: "Missing code parameter" });
}
const [action, value] = state?.split(":");
// Value could be the authId or the githubProviderId
// Value could be the organizationId or the githubProviderId
if (action === "gh_init") {
const octokit = new Octokit({});
@@ -39,17 +41,6 @@ export default async function handler(
},
);
const auth = await findAuthById(value as string);
let adminId = "";
if (auth.role === "owner") {
const admin = await findAdminByAuthId(auth.id);
adminId = admin.adminId;
} else {
const user = await findUserByAuthId(auth.id);
adminId = user.adminId;
}
await createGithub(
{
name: data.name,
@@ -60,7 +51,7 @@ export default async function handler(
githubWebhookSecret: data.webhook_secret,
githubPrivateKey: data.pem,
},
adminId,
value as string,
);
} else if (action === "gh_setup") {
await db