@insforge/react 0.5.7 → 0.5.9
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 +51 -68
- package/dist/atoms.cjs.map +1 -1
- package/dist/atoms.js.map +1 -1
- package/dist/components.cjs +44 -0
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +50 -3
- package/dist/components.d.ts +50 -3
- package/dist/components.js +44 -2
- package/dist/components.js.map +1 -1
- package/dist/forms.cjs.map +1 -1
- package/dist/forms.js.map +1 -1
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +44 -91
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -3
- package/dist/index.d.ts +1 -3
- package/dist/index.js +44 -92
- package/dist/index.js.map +1 -1
- package/package.json +1 -6
- package/dist/routes.cjs +0 -132
- package/dist/routes.cjs.map +0 -1
- package/dist/routes.d.cts +0 -78
- package/dist/routes.d.ts +0 -78
- package/dist/routes.js +0 -130
- package/dist/routes.js.map +0 -1
package/README.md
CHANGED
|
@@ -27,11 +27,11 @@ pnpm add @insforge/react
|
|
|
27
27
|
```
|
|
28
28
|
|
|
29
29
|
**Required Peer Dependencies:**
|
|
30
|
+
|
|
30
31
|
```bash
|
|
31
32
|
npm install react@^19.0.0 react-dom@^19.0.0
|
|
32
33
|
```
|
|
33
34
|
|
|
34
|
-
|
|
35
35
|
#### Environment Variables
|
|
36
36
|
|
|
37
37
|
```bash
|
|
@@ -41,28 +41,19 @@ VITE_INSFORGE_BASE_URL=https://your-project.insforge.app/
|
|
|
41
41
|
|
|
42
42
|
### 2. Setup Provider & Route Guard
|
|
43
43
|
|
|
44
|
-
Wrap your app with `InsforgeProvider
|
|
44
|
+
Wrap your app with `InsforgeProvider`:
|
|
45
45
|
|
|
46
46
|
```tsx
|
|
47
47
|
// src/main.tsx (Vite) or src/index.tsx (CRA)
|
|
48
48
|
import { StrictMode } from 'react';
|
|
49
49
|
import { createRoot } from 'react-dom/client';
|
|
50
|
-
import { InsforgeProvider
|
|
50
|
+
import { InsforgeProvider } from '@insforge/react';
|
|
51
51
|
import App from './App';
|
|
52
52
|
|
|
53
53
|
createRoot(document.getElementById('root')!).render(
|
|
54
54
|
<StrictMode>
|
|
55
|
-
<InsforgeProvider
|
|
56
|
-
|
|
57
|
-
afterSignInUrl="/dashboard"
|
|
58
|
-
>
|
|
59
|
-
<RouteGuard
|
|
60
|
-
builtInAuth
|
|
61
|
-
publicRoutes={['/', '/about']}
|
|
62
|
-
loadingFallback={<div>Loading...</div>}
|
|
63
|
-
>
|
|
64
|
-
<App />
|
|
65
|
-
</RouteGuard>
|
|
55
|
+
<InsforgeProvider baseUrl={import.meta.env.VITE_INSFORGE_BASE_URL}>
|
|
56
|
+
<App />
|
|
66
57
|
</InsforgeProvider>
|
|
67
58
|
</StrictMode>
|
|
68
59
|
);
|
|
@@ -74,24 +65,19 @@ Now you can use authentication components and hooks anywhere in your app:
|
|
|
74
65
|
|
|
75
66
|
```tsx
|
|
76
67
|
// src/App.tsx
|
|
77
|
-
import {
|
|
68
|
+
import { SignInButton, SignUpButton, SignedIn, SignedOut, UserButton } from '@insforge/react';
|
|
78
69
|
|
|
79
70
|
export default function App() {
|
|
80
|
-
const { isSignedIn, isLoaded } = useAuth();
|
|
81
|
-
|
|
82
|
-
if (!isLoaded) {
|
|
83
|
-
return <div>Loading...</div>;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
71
|
return (
|
|
87
72
|
<div>
|
|
88
73
|
<SignedOut>
|
|
89
|
-
<
|
|
74
|
+
<SignInButton />
|
|
75
|
+
<SignUpButton />
|
|
90
76
|
</SignedOut>
|
|
91
77
|
|
|
92
78
|
<SignedIn>
|
|
93
79
|
<nav>
|
|
94
|
-
<UserButton
|
|
80
|
+
<UserButton />
|
|
95
81
|
</nav>
|
|
96
82
|
<h1>Welcome to your dashboard!</h1>
|
|
97
83
|
</SignedIn>
|
|
@@ -216,14 +202,14 @@ function CustomAuthForm() {
|
|
|
216
202
|
|
|
217
203
|
```tsx
|
|
218
204
|
// Authentication state and methods
|
|
219
|
-
const {
|
|
220
|
-
signIn,
|
|
221
|
-
signUp,
|
|
222
|
-
signOut,
|
|
223
|
-
isSignedIn,
|
|
205
|
+
const {
|
|
206
|
+
signIn,
|
|
207
|
+
signUp,
|
|
208
|
+
signOut,
|
|
209
|
+
isSignedIn,
|
|
224
210
|
isLoaded,
|
|
225
|
-
baseUrl,
|
|
226
|
-
afterSignInUrl
|
|
211
|
+
baseUrl, // From provider
|
|
212
|
+
afterSignInUrl, // From provider
|
|
227
213
|
} = useAuth();
|
|
228
214
|
|
|
229
215
|
// Or use useInsforge (same as useAuth)
|
|
@@ -380,10 +366,7 @@ function Dashboard() {
|
|
|
380
366
|
</Protect>
|
|
381
367
|
|
|
382
368
|
{/* Custom condition - e.g., role-based */}
|
|
383
|
-
<Protect
|
|
384
|
-
condition={(user) => user.email.endsWith('@admin.com')}
|
|
385
|
-
redirectTo="/unauthorized"
|
|
386
|
-
>
|
|
369
|
+
<Protect condition={(user) => user.email.endsWith('@admin.com')} redirectTo="/unauthorized">
|
|
387
370
|
<AdminPanel />
|
|
388
371
|
</Protect>
|
|
389
372
|
</div>
|
|
@@ -409,10 +392,7 @@ Redirects to your deployed Insforge Auth pages:
|
|
|
409
392
|
import { InsforgeProvider, RouteGuard } from '@insforge/react';
|
|
410
393
|
|
|
411
394
|
createRoot(document.getElementById('root')!).render(
|
|
412
|
-
<InsforgeProvider
|
|
413
|
-
baseUrl={import.meta.env.VITE_INSFORGE_BASE_URL}
|
|
414
|
-
afterSignInUrl="/dashboard"
|
|
415
|
-
>
|
|
395
|
+
<InsforgeProvider baseUrl={import.meta.env.VITE_INSFORGE_BASE_URL} afterSignInUrl="/dashboard">
|
|
416
396
|
<RouteGuard
|
|
417
397
|
builtInAuth
|
|
418
398
|
publicRoutes={['/', '/about', '/pricing']}
|
|
@@ -425,6 +405,7 @@ createRoot(document.getElementById('root')!).render(
|
|
|
425
405
|
```
|
|
426
406
|
|
|
427
407
|
**Behavior:**
|
|
408
|
+
|
|
428
409
|
- User visits `/sign-in` → Redirects to `baseUrl/auth/sign-in`
|
|
429
410
|
- User visits `/sign-up` → Redirects to `baseUrl/auth/sign-up`
|
|
430
411
|
- User visits `/dashboard` (protected) → Redirects to `baseUrl/auth/sign-in`
|
|
@@ -440,7 +421,7 @@ import { InsforgeProvider, RouteGuard, SignIn, SignUp } from '@insforge/react';
|
|
|
440
421
|
// Simple hash-based routing
|
|
441
422
|
function App() {
|
|
442
423
|
const path = window.location.hash.slice(1) || '/';
|
|
443
|
-
|
|
424
|
+
|
|
444
425
|
return (
|
|
445
426
|
<>
|
|
446
427
|
{path === '/login' && <SignIn />}
|
|
@@ -466,31 +447,32 @@ createRoot(document.getElementById('root')!).render(
|
|
|
466
447
|
```
|
|
467
448
|
|
|
468
449
|
**Behavior:**
|
|
450
|
+
|
|
469
451
|
- User visits `/login` → ✅ Renders `<SignIn />` (in publicRoutes)
|
|
470
452
|
- User visits `/dashboard` (protected) → Redirects to `/login?redirect=/dashboard`
|
|
471
453
|
- After login → Redirects to `/dashboard`
|
|
472
454
|
|
|
473
455
|
#### RouteGuard Props Reference
|
|
474
456
|
|
|
475
|
-
| Prop
|
|
476
|
-
|
|
477
|
-
| `builtInAuth`
|
|
478
|
-
| `publicRoutes`
|
|
479
|
-
| `paths`
|
|
480
|
-
| `paths.signIn`
|
|
481
|
-
| `paths.signUp`
|
|
482
|
-
| `paths.forgotPassword` | `string`
|
|
483
|
-
| `loadingFallback`
|
|
457
|
+
| Prop | Type | Required | Default | Description |
|
|
458
|
+
| ---------------------- | ----------- | -------- | ----------------------------- | ---------------------------------------------------------- |
|
|
459
|
+
| `builtInAuth` | `boolean` | No | `true` | Use external auth pages (`true`) or custom pages (`false`) |
|
|
460
|
+
| `publicRoutes` | `string[]` | No | `[]` | Routes accessible without authentication |
|
|
461
|
+
| `paths` | `object` | No | `{ signIn: '/sign-in', ... }` | Custom auth page paths (when `builtInAuth=false`) |
|
|
462
|
+
| `paths.signIn` | `string` | No | `'/sign-in'` | Custom sign-in page path |
|
|
463
|
+
| `paths.signUp` | `string` | No | `'/sign-up'` | Custom sign-up page path |
|
|
464
|
+
| `paths.forgotPassword` | `string` | No | `'/forgot-password'` | Custom forgot password page path |
|
|
465
|
+
| `loadingFallback` | `ReactNode` | **Yes** | - | Loading UI displayed while checking authentication |
|
|
484
466
|
|
|
485
467
|
**Public Routes with Wildcards:**
|
|
486
468
|
|
|
487
469
|
```tsx
|
|
488
470
|
<RouteGuard
|
|
489
471
|
publicRoutes={[
|
|
490
|
-
'/',
|
|
491
|
-
'/about',
|
|
492
|
-
'/blog/*',
|
|
493
|
-
'/docs/*',
|
|
472
|
+
'/', // Home page
|
|
473
|
+
'/about', // About page
|
|
474
|
+
'/blog/*', // All blog routes
|
|
475
|
+
'/docs/*', // All documentation routes
|
|
494
476
|
]}
|
|
495
477
|
>
|
|
496
478
|
<App />
|
|
@@ -517,8 +499,8 @@ const router = createBrowserRouter([
|
|
|
517
499
|
{ path: '/dashboard', element: <Dashboard /> },
|
|
518
500
|
...getInsforgeRoutes({
|
|
519
501
|
baseUrl: import.meta.env.VITE_INSFORGE_BASE_URL,
|
|
520
|
-
builtInAuth: true
|
|
521
|
-
})
|
|
502
|
+
builtInAuth: true,
|
|
503
|
+
}),
|
|
522
504
|
]);
|
|
523
505
|
|
|
524
506
|
function App() {
|
|
@@ -531,6 +513,7 @@ function App() {
|
|
|
531
513
|
```
|
|
532
514
|
|
|
533
515
|
**Features:**
|
|
516
|
+
|
|
534
517
|
- Pre-configured routes for authentication flows
|
|
535
518
|
- React Router's `Link` and `useSearchParams` integration
|
|
536
519
|
- Optimized navigation with client-side routing
|
|
@@ -563,6 +546,7 @@ export default function RootLayout({ children }) {
|
|
|
563
546
|
```
|
|
564
547
|
|
|
565
548
|
**Features:**
|
|
549
|
+
|
|
566
550
|
- Server-side rendering (SSR) support
|
|
567
551
|
- Middleware-based route protection
|
|
568
552
|
- Next.js `Link` and `useSearchParams` integration
|
|
@@ -614,7 +598,6 @@ Low-level building blocks for complete customization:
|
|
|
614
598
|
|
|
615
599
|
---
|
|
616
600
|
|
|
617
|
-
|
|
618
601
|
## API Reference
|
|
619
602
|
|
|
620
603
|
### InsforgeProvider
|
|
@@ -623,13 +606,13 @@ The root provider component that manages authentication state.
|
|
|
623
606
|
|
|
624
607
|
**Props:**
|
|
625
608
|
|
|
626
|
-
| Prop
|
|
627
|
-
|
|
628
|
-
| `baseUrl`
|
|
629
|
-
| `afterSignInUrl` | `string`
|
|
630
|
-
| `onAuthChange`
|
|
631
|
-
| `onSignIn`
|
|
632
|
-
| `onSignOut`
|
|
609
|
+
| Prop | Type | Required | Default | Description |
|
|
610
|
+
| ---------------- | -------------------------------------- | -------- | ------- | --------------------------------------------------- |
|
|
611
|
+
| `baseUrl` | `string` | **Yes** | - | Your Insforge backend URL |
|
|
612
|
+
| `afterSignInUrl` | `string` | No | `'/'` | Redirect URL after successful sign-in |
|
|
613
|
+
| `onAuthChange` | `(user: InsforgeUser \| null) => void` | No | - | Callback when auth state changes |
|
|
614
|
+
| `onSignIn` | `(authToken: string) => Promise<void>` | No | - | Custom handler after sign-in (e.g., cookie sync) |
|
|
615
|
+
| `onSignOut` | `() => Promise<void>` | No | - | Custom handler after sign-out (e.g., clear cookies) |
|
|
633
616
|
|
|
634
617
|
**Example:**
|
|
635
618
|
|
|
@@ -670,30 +653,30 @@ Primary hook for authentication. Both are aliases for the same hook.
|
|
|
670
653
|
user: InsforgeUser | null;
|
|
671
654
|
isLoaded: boolean;
|
|
672
655
|
isSignedIn: boolean;
|
|
673
|
-
|
|
656
|
+
|
|
674
657
|
// Auth methods
|
|
675
658
|
signIn: (email: string, password: string) => Promise<...>;
|
|
676
659
|
signUp: (email: string, password: string) => Promise<...>;
|
|
677
660
|
signOut: () => Promise<void>;
|
|
678
661
|
updateUser: (data: Partial<InsforgeUser>) => Promise<...>;
|
|
679
662
|
reloadAuth: () => Promise<...>;
|
|
680
|
-
|
|
663
|
+
|
|
681
664
|
// Email verification
|
|
682
665
|
sendVerificationEmail: (email: string) => Promise<...>;
|
|
683
666
|
verifyEmail: (otp: string, email?: string) => Promise<...>;
|
|
684
|
-
|
|
667
|
+
|
|
685
668
|
// Password reset
|
|
686
669
|
sendResetPasswordEmail: (email: string) => Promise<...>;
|
|
687
670
|
resetPassword: (token: string, newPassword: string) => Promise<...>;
|
|
688
671
|
exchangeResetPasswordToken: (email: string, code: string) => Promise<...>;
|
|
689
|
-
|
|
672
|
+
|
|
690
673
|
// OAuth
|
|
691
674
|
loginWithOAuth: (provider: OAuthProvider, redirectTo: string) => Promise<void>;
|
|
692
|
-
|
|
675
|
+
|
|
693
676
|
// Config (from provider)
|
|
694
677
|
baseUrl: string;
|
|
695
678
|
afterSignInUrl: string;
|
|
696
|
-
|
|
679
|
+
|
|
697
680
|
// Public config
|
|
698
681
|
getPublicAuthConfig: () => Promise<...>;
|
|
699
682
|
}
|