Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions apps/dashboard/src/@/api/team/team-invites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,38 @@ export async function getTeamInvites(

return json.result;
}

export async function getTeamInvite(
teamId: string,
inviteId: string,
): Promise<TeamInvite | undefined> {
const authToken = await getAuthToken();

if (!authToken) {
throw new Error("Unauthorized");
}

const res = await fetch(
`${NEXT_PUBLIC_THIRDWEB_API_HOST}/v1/teams/${teamId}/invites/${inviteId}`,
{
headers: {
Authorization: `Bearer ${authToken}`,
},
},
);

if (res.status === 404) {
return undefined;
}

if (!res.ok) {
const errorMessage = await res.text();
throw new Error(errorMessage);
}

const json = (await res.json()) as {
result: TeamInvite;
};

return json.result;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { notFound, redirect } from "next/navigation";
import { getValidAccount } from "@/api/account/get-account";
import { getTeamBySlug, service_getTeamBySlug } from "@/api/team/get-team";
import { getTeamInvite } from "@/api/team/team-invites";
import { JoinTeamPage } from "./JoinTeamPage";

export default async function Page(props: {
Expand All @@ -16,9 +17,12 @@ export default async function Page(props: {
service_getTeamBySlug(team_slug),
]);

// if the user is already a member of the team, redirect to the team
// a member can still hold a pending invite, e.g. for a different role
if (userTeam) {
redirect(`/team/${team_slug}`);
const invite = await getTeamInvite(userTeam.id, invite_id);
if (invite?.status !== "pending") {
redirect(`/team/${team_slug}`);
}
}

if (!inviteTeam) {
Expand Down
Loading