azirid-react 0.6.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +92 -1
- package/dist/index.cjs +456 -355
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +112 -4
- package/dist/index.d.ts +112 -4
- package/dist/index.js +453 -356
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -670,6 +670,89 @@ export default function PayphoneCallbackPage() {
|
|
|
670
670
|
|
|
671
671
|
---
|
|
672
672
|
|
|
673
|
+
## Multi-tenant
|
|
674
|
+
|
|
675
|
+
Every authenticated user always has an active `tenantId` and `tenantRole` in the JWT. On signup, if no `tenantId` is provided, a personal tenant is automatically created and the user becomes `OWNER`.
|
|
676
|
+
|
|
677
|
+
### Tenant switching via `useAzirid()`
|
|
678
|
+
|
|
679
|
+
```tsx
|
|
680
|
+
import { useAzirid } from 'azirid-react'
|
|
681
|
+
|
|
682
|
+
function TenantSwitcher({ tenantId }: { tenantId: string }) {
|
|
683
|
+
const { user, switchTenant } = useAzirid()
|
|
684
|
+
|
|
685
|
+
return (
|
|
686
|
+
<div>
|
|
687
|
+
<p>Active tenant: {user?.tenantId} ({user?.tenantRole})</p>
|
|
688
|
+
<button onClick={() => switchTenant(tenantId)}>Switch</button>
|
|
689
|
+
</div>
|
|
690
|
+
)
|
|
691
|
+
}
|
|
692
|
+
```
|
|
693
|
+
|
|
694
|
+
`switchTenant(tenantId)` calls the refresh endpoint with the new `tenantId`, updates the access token in memory, and invalidates all queries — no re-login required.
|
|
695
|
+
|
|
696
|
+
### `useTenants`
|
|
697
|
+
|
|
698
|
+
List all tenants the authenticated user belongs to.
|
|
699
|
+
|
|
700
|
+
```tsx
|
|
701
|
+
import { useTenants } from 'azirid-react'
|
|
702
|
+
|
|
703
|
+
function TenantList() {
|
|
704
|
+
const { data: tenants, isLoading } = useTenants()
|
|
705
|
+
|
|
706
|
+
if (isLoading) return <Spinner />
|
|
707
|
+
|
|
708
|
+
return (
|
|
709
|
+
<ul>
|
|
710
|
+
{tenants?.map((t) => (
|
|
711
|
+
<li key={t.tenantId}>
|
|
712
|
+
{t.name} — {t.role}
|
|
713
|
+
</li>
|
|
714
|
+
))}
|
|
715
|
+
</ul>
|
|
716
|
+
)
|
|
717
|
+
}
|
|
718
|
+
```
|
|
719
|
+
|
|
720
|
+
### `useTenantMembers`
|
|
721
|
+
|
|
722
|
+
List all members of a specific tenant. The authenticated user must be a member.
|
|
723
|
+
|
|
724
|
+
```tsx
|
|
725
|
+
import { useTenantMembers } from 'azirid-react'
|
|
726
|
+
|
|
727
|
+
function MemberList({ tenantId }: { tenantId: string }) {
|
|
728
|
+
const { data: members } = useTenantMembers(tenantId)
|
|
729
|
+
|
|
730
|
+
return (
|
|
731
|
+
<ul>
|
|
732
|
+
{members?.map((m) => (
|
|
733
|
+
<li key={m.id}>
|
|
734
|
+
{m.user.email} — {m.role}
|
|
735
|
+
</li>
|
|
736
|
+
))}
|
|
737
|
+
</ul>
|
|
738
|
+
)
|
|
739
|
+
}
|
|
740
|
+
```
|
|
741
|
+
|
|
742
|
+
### `useSwitchTenant`
|
|
743
|
+
|
|
744
|
+
Headless hook for tenant switching (same as `switchTenant` from `useAzirid()`, but usable outside the main context hook).
|
|
745
|
+
|
|
746
|
+
```tsx
|
|
747
|
+
import { useSwitchTenant } from 'azirid-react'
|
|
748
|
+
|
|
749
|
+
const { switchTenant } = useSwitchTenant()
|
|
750
|
+
|
|
751
|
+
await switchTenant('tenant-id-here')
|
|
752
|
+
```
|
|
753
|
+
|
|
754
|
+
---
|
|
755
|
+
|
|
673
756
|
## Referrals
|
|
674
757
|
|
|
675
758
|
All referral hooks require `<AziridProvider>` in the tree and an authenticated user.
|
|
@@ -1255,7 +1338,7 @@ import type {
|
|
|
1255
1338
|
|
|
1256
1339
|
| Type | Description |
|
|
1257
1340
|
| --- | --- |
|
|
1258
|
-
| `AuthUser` | Authenticated user object (`id`, `email`, `
|
|
1341
|
+
| `AuthUser` | Authenticated user object (`id`, `email`, `tenantId`, `tenantRole`, `appId`, ...) — `tenantId` and `tenantRole` are always present |
|
|
1259
1342
|
| `AuthSuccessResponse` | Login/signup response (`accessToken`, `user`) |
|
|
1260
1343
|
| `AuthState` | Full auth state (`user`, `accessToken`, `isAuthenticated`, `isLoading`, `error`) |
|
|
1261
1344
|
| `SignupData` | Signup payload (`email`, `password`, `acceptedTosVersion?`, `referralCode?`, ...) |
|
|
@@ -1264,6 +1347,14 @@ import type {
|
|
|
1264
1347
|
| `AziridProviderProps` | All provider props (see table above) |
|
|
1265
1348
|
| `AziridContextValue` | Context value returned by `useAzirid()` |
|
|
1266
1349
|
|
|
1350
|
+
### Tenant Types
|
|
1351
|
+
|
|
1352
|
+
| Type | Description |
|
|
1353
|
+
| --- | --- |
|
|
1354
|
+
| `TenantWithRole` | Tenant membership (`tenantId`, `name`, `slug`, `role: 'OWNER' \| 'MEMBER'`, `joinedAt`) |
|
|
1355
|
+
| `TenantMemberInfo` | Tenant member (`id`, `role`, `joinedAt`, `user: { id, email, firstName, lastName }`) |
|
|
1356
|
+
| `CreateTenantData` | Create tenant payload (`name`, `description?`) |
|
|
1357
|
+
|
|
1267
1358
|
### Billing Types
|
|
1268
1359
|
|
|
1269
1360
|
| Type | Description |
|