rbac-shield 0.1.11 β 0.1.12
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 +56 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,11 +26,11 @@ Built for modern web development with **React 19**, **TypeScript 5**, and **Next
|
|
|
26
26
|
|
|
27
27
|
## β¨ Features
|
|
28
28
|
|
|
29
|
-
- π― **Type-Safe Permissions**:
|
|
29
|
+
- π― **Type-Safe Permissions**: Typescript "Prettify" helpers ensure tooltips show exact prop shapes, amazing IntelliSense.
|
|
30
30
|
- π **High Performance**: Optimized with React Context and memoization. Permission checks are < 1ms.
|
|
31
31
|
- π’ **Multi-Tenant Native**: Switch between multiple organizations/roles instantly without page reloads.
|
|
32
|
+
- β‘ **Zero Loading States**: Support for `initialData` prop allows instant hydration from server-side data.
|
|
32
33
|
- π‘οΈ **Route Protection**: Declarative client-side guards with automatic handling of loading states and redirects.
|
|
33
|
-
- π **SSR & Hydration Safe**: Built from the ground up for Next.js App Routerβno hydration mismatches.
|
|
34
34
|
- π **Universal Support**: Works seamlessly in **Client Components**, **Server Components**, and **Middleware**.
|
|
35
35
|
- π¦ **Zero Dependencies**: Lightweight (~35KB) and built entirely on standard React APIs.
|
|
36
36
|
|
|
@@ -306,14 +306,63 @@ Returns `boolean`. True if user has **at least one** of the listed permissions.
|
|
|
306
306
|
|
|
307
307
|
Returns `boolean`. True only if user has **every single** listed permission.
|
|
308
308
|
|
|
309
|
+
### 8. SSR Support (Eliminate Loading States)
|
|
310
|
+
|
|
311
|
+
Prevent the "flicker" of loading states by passing server-side permissions directly to the provider.
|
|
312
|
+
|
|
313
|
+
```tsx
|
|
314
|
+
// app/layout.tsx (Server Component)
|
|
315
|
+
import { RBACProvider } from "@/lib/rbac";
|
|
316
|
+
import { getSession } from "@/lib/auth"; // Your auth logic
|
|
317
|
+
|
|
318
|
+
export default async function RootLayout({ children }) {
|
|
319
|
+
const session = await getSession();
|
|
320
|
+
|
|
321
|
+
// Prepare valid initial data matches TenantAuthInput[]
|
|
322
|
+
const initialData = session
|
|
323
|
+
? [
|
|
324
|
+
{
|
|
325
|
+
tenantId: session.orgId,
|
|
326
|
+
permissions: session.permissions, // string[] from DB is fine!
|
|
327
|
+
},
|
|
328
|
+
]
|
|
329
|
+
: [];
|
|
330
|
+
|
|
331
|
+
return (
|
|
332
|
+
<html>
|
|
333
|
+
<body>
|
|
334
|
+
<RBACProvider initialData={initialData}>{children}</RBACProvider>
|
|
335
|
+
</body>
|
|
336
|
+
</html>
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
---
|
|
342
|
+
|
|
343
|
+
## π API Reference
|
|
344
|
+
|
|
345
|
+
### `<RBACProvider>`
|
|
346
|
+
|
|
347
|
+
Top-level provider component.
|
|
348
|
+
|
|
349
|
+
- **initialData**: (Optional) `TenantAuthInput[]`. Hydrate state immediately (great for SSR).
|
|
350
|
+
- **debug**: (Optional) `boolean`. Log permission checks to console.
|
|
351
|
+
|
|
352
|
+
```tsx
|
|
353
|
+
<RBACProvider initialData={serverPerms} debug={true}>
|
|
354
|
+
{children}
|
|
355
|
+
</RBACProvider>
|
|
356
|
+
```
|
|
357
|
+
|
|
309
358
|
### `useStore()`
|
|
310
359
|
|
|
311
360
|
Access raw state and actions:
|
|
312
361
|
|
|
313
|
-
- `
|
|
314
|
-
- `
|
|
315
|
-
- `
|
|
316
|
-
- `
|
|
362
|
+
- `setAuth(authData)`: Accepts simple `string[]` for permissions. No need to cast API responses!
|
|
363
|
+
- `switchTenant(id)`: Change active context.
|
|
364
|
+
- `isLoading`: `boolean`.
|
|
365
|
+
- `activeTenantId`: `string | null`.
|
|
317
366
|
|
|
318
367
|
---
|
|
319
368
|
|
|
@@ -383,4 +432,4 @@ We welcome contributions! Please open an issue or submit a PR on our [GitHub rep
|
|
|
383
432
|
|
|
384
433
|
## π License
|
|
385
434
|
|
|
386
|
-
MIT Β© [Arif Hossain Roman](https://github.com/
|
|
435
|
+
MIT Β© [Arif Hossain Roman](https://github.com/devnuckles)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rbac-shield",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
4
4
|
"description": "A production-ready, type-safe Role-Based Access Control (RBAC) system for Next.js applications with multi-tenant support",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|