@authu/react 1.0.15 → 1.0.31

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.
Files changed (2) hide show
  1. package/README.md +28 -1
  2. package/package.json +10 -9
package/README.md CHANGED
@@ -61,7 +61,7 @@ function Profile() {
61
61
 
62
62
  ### 3. Protect Routes
63
63
 
64
- Use `PrivateRoute` to protect authenticated routes:
64
+ Use `PrivateRoute` to protect authenticated routes. It automatically triggers the OAuth login flow when the user is not authenticated:
65
65
 
66
66
  ```tsx
67
67
  import {PrivateRoute} from '@authu/react';
@@ -83,6 +83,27 @@ function AppRoutes() {
83
83
  }
84
84
  ```
85
85
 
86
+ #### PrivateRoute Props
87
+
88
+ | Prop | Type | Default | Description |
89
+ |------|------|---------|-------------|
90
+ | `children` | `ReactNode` | - | Content to render when authenticated |
91
+ | `fallback` | `ReactNode` | `null` | Content to show while loading or redirecting |
92
+ | `loginOnUnauthenticated` | `boolean` | `true` | Auto-trigger login when not authenticated |
93
+
94
+ #### Automatic Login Flow
95
+
96
+ When `loginOnUnauthenticated` is `true` (default), visiting a protected route triggers:
97
+
98
+ 1. `PrivateRoute` checks `isAuthenticated`
99
+ 2. If not authenticated → calls `login()` automatically
100
+ 3. User is redirected to AuthU login page
101
+ 4. After login, AuthU redirects back to the app
102
+ 5. `AuthUProvider` exchanges the code for tokens
103
+ 6. User is now authenticated and sees the protected content
104
+
105
+ This enables seamless SSO: users logged into AuthU are automatically authenticated in the app without extra clicks.
106
+
86
107
  ### 4. Get Access Token for API Calls
87
108
 
88
109
  Use `useApiToken` to get tokens for authenticated API requests:
@@ -166,6 +187,12 @@ The `--access public` flag is required for scoped packages.
166
187
 
167
188
  ## Changelog
168
189
 
190
+ ### 1.0.15
191
+
192
+ - **Feature**: Added `loginOnUnauthenticated` prop to `PrivateRoute` for automatic login triggering
193
+ - **Feature**: Added `fallback` prop to `PrivateRoute` for custom loading states
194
+ - **Docs**: Improved documentation for automatic SSO flow
195
+
169
196
  ### 1.0.10
170
197
 
171
198
  - **Fix**: Changed PKCE storage from `sessionStorage` to `localStorage` to prevent state/code_verifier loss during cross-domain OAuth redirects
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@authu/react",
3
- "version": "1.0.15",
3
+ "version": "1.0.31",
4
4
  "description": "React SDK for AuthU - Centralized Multi-Tenant Authentication Service",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -15,6 +15,14 @@
15
15
  "files": [
16
16
  "dist"
17
17
  ],
18
+ "scripts": {
19
+ "build": "tsc",
20
+ "dev": "tsc --watch",
21
+ "eslint": "eslint src --cache",
22
+ "typecheck": "tsc --noEmit",
23
+ "lint": "pnpm run eslint && pnpm run typecheck",
24
+ "prepublishOnly": "pnpm run build"
25
+ },
18
26
  "keywords": [
19
27
  "authu",
20
28
  "auth",
@@ -39,12 +47,5 @@
39
47
  "react": "^19.0.0",
40
48
  "typescript": "^5.7.3",
41
49
  "typescript-eslint": "^8.44.1"
42
- },
43
- "scripts": {
44
- "build": "tsc",
45
- "dev": "tsc --watch",
46
- "eslint": "eslint src --cache",
47
- "typecheck": "tsc --noEmit",
48
- "lint": "pnpm run eslint && pnpm run typecheck"
49
50
  }
50
- }
51
+ }