Loading...
Loading...
Learn how to switch between user, team, and tenant contexts in the EventZR platform. Context switching is central to multi-tenant operations and ensures correct data isolation.
Every API request in EventZR operates within a context defined by three headers:x-tenant-id,x-actor-id, andx-team-id. These headers determine which tenant's data is accessed, which user is performing the action, and which team scope applies to the operation.
| Header | Type | Description |
|---|---|---|
| x-tenant-id | UUID | Tenant context for data isolation (required) |
| x-actor-id | UUID | Authenticated user performing the action |
| x-team-id | UUID | Team scope (optional, for team-level operations) |
Include the context headers in every API request. The JWT token already contains tenantId and userId claims, but explicit headers allow context overriding for admin operations.
const response = await fetch('/api/svc/event/v1/events', {
headers: {
'Authorization': 'Bearer <jwt-token>',
'x-tenant-id': 'tenant-uuid',
'x-actor-id': 'user-uuid',
'x-team-id': 'team-uuid', // optional
'Content-Type': 'application/json',
},
});Use the useContextSwitcher hook from @eventzr/react-hooks to manage context switching in React applications.
import { useContextSwitcher } from '@eventzr/react-hooks';
function MyComponent() {
const { currentTenant, currentTeam, switchTenant, switchTeam } = useContextSwitcher();
return (
<div>
<p>Tenant: {currentTenant.name}</p>
<p>Team: {currentTeam?.name ?? 'No team'}</p>
<button onClick={() => switchTeam('new-team-id')}>
Switch Team
</button>
</div>
);
}x-tenant-id in every API call.@eventzr/auth.