mirror of
https://github.com/better-auth/better-auth.git
synced 2026-05-26 00:46:44 -05:00
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:
committed by
GitHub
parent
0ca7df6914
commit
a24761eb3b
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user