Skip to content

Commit

Permalink
Merge pull request #487 from clerkinc/backend-org-invitation-metadata
Browse files Browse the repository at this point in the history
feat(backend-core): Organization invitation metadata
  • Loading branch information
gkats authored Nov 1, 2022
2 parents 18dd5c4 + 7bc4691 commit 2685b27
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/backend-core/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,16 @@ Create an invitation to join an organization and send an email to the email addr

You must pass the ID of the user that invites the new member as `inviterUserId`. The inviter user must be an administrator in the organization.

You can optionally pass metadata for the organization invitation with the `publicMetadata` field. These metadata will be accessible from both the Frontend and the Backend. Once the invitation is accepted, the metadata will be transferred to the newly created organization membership.

Available parameters:

- _organizationId_ The unique ID of the organization the invitation is about.
- _emailAddress_ The email address of the member that's going to be invited to join the organization.
- _role_ The new member's role in the organization.
- _inviterUserId_ The ID of the organization administrator that invites the new member.
- _redirectUrl_ An optional URL to redirect to after the invited member clicks the link from the invitation email.
- _publicMetadata_ Optionally pass metadata for the organization invitation which will be visible to both your Frontend and Backend.

```js
const invitation = await clerkAPI.organizations.createOrganizationInvitation({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,13 @@ test('createOrganizationInvitation() creates an invitation for an organization',
const status: OrganizationInvitationStatus = 'pending';
const emailAddress = 'invitation@example.com';
const redirectUrl = 'https://example.com';
const publicMetadata = { foo: 'bar' };
const resJSON: OrganizationInvitationJSON = {
object: ObjectType.OrganizationInvitation,
id: 'orginv_randomid',
role,
status,
public_metadata: publicMetadata,
email_address: emailAddress,
organization_id: organizationId,
created_at: 1612378465,
Expand All @@ -366,6 +368,7 @@ test('createOrganizationInvitation() creates an invitation for an organization',
emailAddress,
role,
redirectUrl,
publicMetadata,
inviterUserId: 'user_randomid',
});
expect(orgInvitation).toEqual(OrganizationInvitation.fromJSON(resJSON));
Expand All @@ -381,6 +384,7 @@ test('getPendingOrganizationInvitationList() returns a list of organization memb
email_address: 'invited@example.org',
organization_id: organizationId,
status: 'pending',
public_metadata: {},
created_at: 1612378465,
updated_at: 1612378465,
},
Expand Down Expand Up @@ -408,6 +412,7 @@ test('revokeOrganizationInvitation() revokes an organization invitation', async
email_address: 'invited@example.org',
organization_id: organizationId,
status: 'revoked',
public_metadata: {},
created_at: 1612378465,
updated_at: 1612378465,
};
Expand Down
1 change: 1 addition & 0 deletions packages/backend-core/src/api/endpoints/OrganizationApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type CreateOrganizationInvitationParams = {
inviterUserId: string;
emailAddress: string;
role: OrganizationMembershipRole;
publicMetadata?: Record<string, unknown>;
redirectUrl?: string;
};

Expand Down
1 change: 1 addition & 0 deletions packages/backend-core/src/api/resources/JSON.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export interface OrganizationJSON extends ClerkResourceJSON {
export interface OrganizationInvitationJSON extends ClerkResourceJSON {
email_address: string;
organization_id: string;
public_metadata: Record<string, unknown>;
role: OrganizationMembershipRole;
status: OrganizationInvitationStatus;
created_at: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export class OrganizationInvitation {
readonly organizationId: string,
readonly createdAt: number,
readonly updatedAt: number,
readonly publicMetadata: Record<string, unknown> = {},
readonly status?: OrganizationInvitationStatus,
) {}

Expand All @@ -20,6 +21,7 @@ export class OrganizationInvitation {
data.organization_id,
data.created_at,
data.updated_at,
data.public_metadata,
data.status,
);
}
Expand Down

0 comments on commit 2685b27

Please sign in to comment.