feat(organization): allow invited users to see organization name (#6602)

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Gautam Manchandani
2025-12-08 12:20:44 +05:30
committed by GitHub
parent 0ca7df6914
commit a24761eb3b
3 changed files with 81 additions and 2 deletions

View File

@@ -860,11 +860,21 @@ export const getOrgAdapter = <O extends OrganizationOptions>(
},
listUserInvitations: async (email: string) => {
const adapter = await getCurrentAdapter(baseAdapter);
const invitations = await adapter.findMany<InferInvitation<O, false>>({
const invitations = await adapter.findMany<
InferInvitation<O, false> & {
organization: InferOrganization<O, false>;
}
>({
model: "invitation",
where: [{ field: "email", value: email.toLowerCase() }],
join: {
organization: true,
},
});
return invitations;
return invitations.map(({ organization, ...inv }) => ({
...inv,
organizationName: organization.name,
}));
},
createInvitation: async ({
invitation,

View File

@@ -1118,6 +1118,7 @@ describe("organization", async (it) => {
},
});
expect(userInvitations.data?.[0]!.id).toBe(invitation.data?.id);
expect(userInvitations.data?.[0]!.organizationName).toBe(orgRng);
expect(userInvitations.data?.length).toBe(1);
});

View File

@@ -1088,6 +1088,74 @@ export const listUserInvitations = <O extends OrganizationOptions>(
.optional(),
})
.optional(),
metadata: {
openapi: {
description: "List all invitations a user has received",
responses: {
"200": {
description: "Success",
content: {
"application/json": {
schema: {
type: "array",
items: {
type: "object",
properties: {
id: {
type: "string",
},
email: {
type: "string",
},
role: {
type: "string",
},
organizationId: {
type: "string",
},
organizationName: {
type: "string",
},
inviterId: {
type: "string",
description:
"The ID of the user who created the invitation",
},
teamId: {
type: "string",
description:
"The ID of the team associated with the invitation",
nullable: true,
},
status: {
type: "string",
},
expiresAt: {
type: "string",
},
createdAt: {
type: "string",
},
},
required: [
"id",
"email",
"role",
"organizationId",
"organizationName",
"inviterId",
"status",
"expiresAt",
"createdAt",
],
},
},
},
},
},
},
},
},
},
async (ctx) => {
const session = await getSessionFromCtx(ctx);