Tutorial: Accepting Invitations
This tutorial walks through the full invite-accept registration flow — from sending an invitation to a new user registering and receiving tokens.
Prerequisites
- A valid Buttrbase app with credentials (
bb_live_…orbb_test_…) - An existing organisation UUID
Step 1 — Send the invitation
Use the admin dashboard or the API to invite a new team member.
POST /api/invitations
Authorization: Bearer
Content-Type: application/json{
"email": "alice@example.com",
"org_uuid": "4cbb47e4-...",
"team_id": 7,
"role_id": 3
}
The invitee receives an email containing the token UUID.
Step 2 — User opens the invite link
Your frontend receives the token from the URL, e.g.:
https://yourapp.com/accept-invite?token=e4b2c1a0-...
Step 3 — Check org availability (optional)
If your registration form lets the user choose an org name, validate it first:
const res = await fetch(/api/auth/orgs/check?name=${encodeURIComponent(name)});
const { data } = await res.json();
if (!data.available) showError('That organisation name is already taken.');
Step 4 — Get the client IP for timezone pre-fill
const geo = await fetch('/api/geo/ip').then(r => r.json());
const tz = Intl.DateTimeFormat().resolvedOptions().timeZone; // browser-side
Step 5 — Submit the registration form
const res = await fetch('/api/auth/invite/accept', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
token: 'e4b2c1a0-...',
first_name: 'Alice',
last_name: 'Smith',
username: 'asmith',
password: 'S3cr3t!99',
}),
});const { data } = await res.json();
// data.access_token — store in memory / httpOnly cookie
// data.refresh_token — store securely
// data.role — "employee"
Step 6 — Store tokens and redirect
sessionStorage.setItem('access_token', data.access_token);
window.location.href = '/dashboard';
Rust SDK equivalent
use buttrbase_sdk::models::InviteAcceptRequest;let response = client.invite_accept(&InviteAcceptRequest {
token: "e4b2c1a0-...",
first_name: "Alice",
last_name: "Smith",
username: "asmith",
password: "S3cr3t!99",
phone: None,
}).await?;
println!("Logged in as {} with role {}", response.user_uuid, response.role);
Using FlatBuffers for high-throughput registration
If you are bulk-registering users (e.g. employee import), add the
Accept: application/x-flatbuffers header to receive the binary response
and skip JSON parsing entirely:
// The SDK's request() method handles content negotiation automatically
// when you build the client with new_with_credentials().