Skip to main content
Manage a store’s team from your own server code when you migrate staff from another system, sync people from an identity provider, or build your own team screens. Every change runs through a workflow that validates the owner rules and emits an event.

Before you begin

You need the following in place:
  • A store id, such as sel_01JD8Q1234567
  • A notification provider for email, if you send invite links from a subscriber

Invite and onboard a member

1

Create the invite

createMemberInvitesWorkflow takes an array of invites, each with seller_id, email, and role_id. It signs a token for each one and fails if an email already belongs to the store.
2

Send the invite link

The workflow emits member_invite.created once per invite, with id, token, and expires_at. Mercur doesn’t email team invites itself, so send the link from a subscriber.
src/subscribers/member-invite-created.ts
3

Accept the invite

When the invitee signs up or signs in, run acceptMemberInviteWorkflow with the token and their auth identity. It returns the member.
The workflow upserts the member by email, creates the membership with the invite’s role, and deletes the invite. Pass member_id when the person is already a member of another store, so the workflow leaves their auth identity as it is.

Resend or revoke an invite

resendMemberInviteWorkflow takes invite_id and seller_id. It deletes the invite and creates a fresh one with a new token and expiry, then emits member_invite.created again. deleteMemberInviteWorkflow takes invite_id and deletes the invite without a replacement.

Add an existing member directly

Skip the invite when the person already has a Member record, for example after a migration. addSellerMemberWorkflow creates the membership and returns it.
The membership is unique on (seller_id, member_id), so adding the same member twice fails.

Change a role or remove a member

Both workflows take the membership id, seller_member_id, not the member id. Both reject the owner membership with a NOT_ALLOWED error.
Removing a membership keeps the Member record, so the person keeps access to their other stores.

Update a member’s profile

updateMemberWorkflow changes first_name, last_name, and locale on members that match a selector. It exposes a membersUpdated hook and doesn’t emit an event.

Next steps