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

@@ -0,0 +1,30 @@
import { Button } from "@/components/ui/button";
import { authClient } from "@/lib/auth";
import { useRouter } from "next/router";
export const AcceptInvitation = () => {
const { query } = useRouter();
const invitationId = query["accept-invitation"];
// const { data: organization } = api.organization.getById.useQuery({
// id: id as string
// })
return (
<div>
<Button
onClick={async () => {
const result = await authClient.organization.acceptInvitation({
invitationId: invitationId as string,
});
console.log(result);
}}
>
Accept Invitation
</Button>
</div>
);
};
export default AcceptInvitation;

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