@insforge/nextjs 0.10.2 → 0.10.4
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 +335 -330
- package/dist/api/route-handlers.d.ts +63 -4
- package/dist/client-boundary/hooks.d.ts +9 -46
- package/dist/client-boundary/provider.d.ts +43 -0
- package/dist/esm/api/index.js.map +1 -1
- package/dist/esm/api/route-handlers.js +14 -45
- package/dist/esm/api/route-handlers.js.map +1 -1
- package/dist/esm/client-boundary/components.js.map +1 -1
- package/dist/esm/client-boundary/hooks.js.map +1 -1
- package/dist/esm/client-boundary/provider.js +3 -3
- package/dist/esm/client-boundary/provider.js.map +1 -1
- package/dist/esm/index.js +5 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/middleware/InsforgeMiddleware.js +1 -1
- package/dist/esm/middleware/InsforgeMiddleware.js.map +1 -1
- package/dist/esm/middleware/index.js +1 -3
- package/dist/esm/middleware/index.js.map +1 -1
- package/dist/esm/navigation/NextNavigationAdapter.js.map +1 -1
- package/dist/esm/navigation/index.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/middleware/InsforgeMiddleware.d.ts +119 -1
- package/dist/navigation/NextNavigationAdapter.d.ts +5 -0
- package/package.json +58 -60
- package/src/styles.css +1 -1
|
@@ -1,15 +1,133 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
2
|
|
|
3
3
|
interface InsforgeMiddlewareConfig {
|
|
4
|
+
/**
|
|
5
|
+
* Base URL of your Insforge backend
|
|
6
|
+
* @example 'https://your-backend.com' or 'http://localhost:3001'
|
|
7
|
+
*/
|
|
4
8
|
baseUrl: string;
|
|
9
|
+
/**
|
|
10
|
+
* Routes that are public and don't require authentication
|
|
11
|
+
* @default ['/']
|
|
12
|
+
* @example ['/sign-in', '/sign-up', '/', '/about']
|
|
13
|
+
*/
|
|
5
14
|
publicRoutes?: string[];
|
|
15
|
+
/**
|
|
16
|
+
* Local route path for sign-in (can be customized to any path like '/login')
|
|
17
|
+
* When using built-in auth, this will redirect to backend's `/auth/sign-in`
|
|
18
|
+
* @default '/sign-in'
|
|
19
|
+
*/
|
|
6
20
|
signInUrl?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Local route path for sign-up (can be customized to any path like '/register')
|
|
23
|
+
* When using built-in auth, this will redirect to backend's `/auth/sign-up`
|
|
24
|
+
* @default '/sign-up'
|
|
25
|
+
*/
|
|
7
26
|
signUpUrl?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Local route path for forgot password
|
|
29
|
+
* When using built-in auth, this will redirect to backend's `/auth/forgot-password`
|
|
30
|
+
* @default '/forgot-password'
|
|
31
|
+
*/
|
|
8
32
|
forgotPasswordUrl?: string;
|
|
33
|
+
/**
|
|
34
|
+
* URL to redirect to after successful authentication
|
|
35
|
+
* When user completes sign-in/sign-up, they will be redirected to this URL with token in URL
|
|
36
|
+
* @default '/'
|
|
37
|
+
*/
|
|
9
38
|
afterSignInUrl?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Cookie name for the auth token
|
|
41
|
+
* @default 'insforge_token'
|
|
42
|
+
*/
|
|
10
43
|
cookieName?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Whether to use built-in authentication pages hosted on the backend
|
|
46
|
+
* - When true: redirects to backend's `/auth/sign-in` and `/auth/sign-up` pages
|
|
47
|
+
* - When false: redirects to local sign-in/sign-up pages (you provide your own components)
|
|
48
|
+
* @default true
|
|
49
|
+
*/
|
|
11
50
|
useBuiltInAuth?: boolean;
|
|
12
51
|
}
|
|
13
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Creates Next.js middleware for protecting routes with Insforge authentication.
|
|
54
|
+
*
|
|
55
|
+
* This middleware provides lightweight route protection by:
|
|
56
|
+
* - Detecting and storing auth tokens from URL parameters (after backend redirect)
|
|
57
|
+
* - Checking for auth token presence in cookies
|
|
58
|
+
* - Redirecting unauthenticated users to sign-in page
|
|
59
|
+
* - Allowing public routes to be accessed without authentication
|
|
60
|
+
* - Mapping local auth routes to backend's fixed paths when using built-in auth
|
|
61
|
+
*
|
|
62
|
+
* **How Authentication Flow Works:**
|
|
63
|
+
* 1. User visits protected route → Middleware checks for token
|
|
64
|
+
* 2. No token → Redirects to sign-in (backend or local)
|
|
65
|
+
* 3. User accesses auth page (e.g., /sign-in) → Redirects to backend with afterSignInUrl as redirect target
|
|
66
|
+
* 4. After sign-in → Backend redirects to `yourapp.com/afterSignInUrl?access_token=xxx&user_id=xxx...`
|
|
67
|
+
* 5. Middleware detects `access_token` in URL → Stores in HTTP-only cookie → Cleans URL → Allows access
|
|
68
|
+
* 6. SDK also detects token from URL → Stores in localStorage → Updates auth state
|
|
69
|
+
*
|
|
70
|
+
* **Important Notes:**
|
|
71
|
+
* - This middleware only checks if a token exists, it doesn't validate it
|
|
72
|
+
* - Tokens from URL are automatically extracted and stored in cookies
|
|
73
|
+
* - When `useBuiltInAuth: true`, local routes map to backend's fixed auth paths
|
|
74
|
+
* - You can customize local route paths (e.g., `/login`) while backend paths remain fixed
|
|
75
|
+
* - After successful auth, users are redirected to `afterSignInUrl` (default: `/`), not back to the auth page
|
|
76
|
+
*
|
|
77
|
+
* @param config - Middleware configuration
|
|
78
|
+
* @returns Next.js middleware function
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* // middleware.ts - Using built-in auth
|
|
83
|
+
* import { InsforgeMiddleware } from '@insforge/nextjs/middleware';
|
|
84
|
+
*
|
|
85
|
+
* export default InsforgeMiddleware({
|
|
86
|
+
* baseUrl: process.env.INSFORGE_BASE_URL!,
|
|
87
|
+
* publicRoutes: ['/', '/about'],
|
|
88
|
+
* afterSignInUrl: '/', // Redirect here after successful auth
|
|
89
|
+
* useBuiltInAuth: true,
|
|
90
|
+
* });
|
|
91
|
+
*
|
|
92
|
+
* export const config = {
|
|
93
|
+
* matcher: ['/((?!_next|api|.*\\..*).*)'],
|
|
94
|
+
* };
|
|
95
|
+
* ```
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* // middleware.ts - Custom local auth pages with custom paths
|
|
100
|
+
* import { InsforgeMiddleware } from '@insforge/nextjs/middleware';
|
|
101
|
+
*
|
|
102
|
+
* export default InsforgeMiddleware({
|
|
103
|
+
* baseUrl: process.env.INSFORGE_BASE_URL!,
|
|
104
|
+
* publicRoutes: ['/login', '/register', '/', '/about'],
|
|
105
|
+
* signInUrl: '/login',
|
|
106
|
+
* signUpUrl: '/register',
|
|
107
|
+
* afterSignInUrl: '/dashboard',
|
|
108
|
+
* useBuiltInAuth: false,
|
|
109
|
+
* });
|
|
110
|
+
*
|
|
111
|
+
* export const config = {
|
|
112
|
+
* matcher: ['/((?!_next|api|.*\\..*).*)'],
|
|
113
|
+
* };
|
|
114
|
+
* ```
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```ts
|
|
118
|
+
* // middleware.ts - Built-in auth with custom auth route paths
|
|
119
|
+
* import { InsforgeMiddleware } from '@insforge/nextjs/middleware';
|
|
120
|
+
*
|
|
121
|
+
* export default InsforgeMiddleware({
|
|
122
|
+
* baseUrl: 'https://your-backend.com',
|
|
123
|
+
* signInUrl: '/login',
|
|
124
|
+
* signUpUrl: '/register',
|
|
125
|
+
* forgotPasswordUrl: '/forgot',
|
|
126
|
+
* afterSignInUrl: '/dashboard',
|
|
127
|
+
* useBuiltInAuth: true,
|
|
128
|
+
* });
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
declare function InsforgeMiddleware(config: InsforgeMiddlewareConfig): (request: NextRequest) => NextResponse<unknown>;
|
|
14
132
|
|
|
15
133
|
export { InsforgeMiddleware, type InsforgeMiddlewareConfig };
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { NavigationAdapter } from '@insforge/react/navigation';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Next.js navigation adapter
|
|
5
|
+
* Uses Next.js's useSearchParams hook and Link component
|
|
6
|
+
* Provides optimized navigation with prefetching and client-side routing
|
|
7
|
+
*/
|
|
3
8
|
declare const NextNavigationAdapter: NavigationAdapter;
|
|
4
9
|
|
|
5
10
|
export { NextNavigationAdapter };
|
package/package.json
CHANGED
|
@@ -1,60 +1,58 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@insforge/nextjs",
|
|
3
|
-
"version": "0.10.
|
|
4
|
-
"description": "Pre-built authentication UI components for Next.js with Insforge backend - zero configuration required",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"types": "./dist/index.d.ts",
|
|
7
|
-
"exports": {
|
|
8
|
-
".": {
|
|
9
|
-
"types": "./dist/index.d.ts",
|
|
10
|
-
"import": "./dist/esm/index.js"
|
|
11
|
-
},
|
|
12
|
-
"./middleware": {
|
|
13
|
-
"types": "./dist/middleware/index.d.ts",
|
|
14
|
-
"import": "./dist/esm/middleware/index.js"
|
|
15
|
-
},
|
|
16
|
-
"./api": {
|
|
17
|
-
"types": "./dist/api/index.d.ts",
|
|
18
|
-
"import": "./dist/esm/api/index.js"
|
|
19
|
-
},
|
|
20
|
-
"./styles.css": "./src/styles.css"
|
|
21
|
-
},
|
|
22
|
-
"files": [
|
|
23
|
-
"dist",
|
|
24
|
-
"src/styles.css",
|
|
25
|
-
"README.md"
|
|
26
|
-
],
|
|
27
|
-
"scripts": {
|
|
28
|
-
"build": "tsup",
|
|
29
|
-
"dev": "tsup --watch",
|
|
30
|
-
"type-check": "tsc --noEmit"
|
|
31
|
-
},
|
|
32
|
-
"keywords": [
|
|
33
|
-
"insforge",
|
|
34
|
-
"nextjs",
|
|
35
|
-
"authentication",
|
|
36
|
-
"auth",
|
|
37
|
-
"ui",
|
|
38
|
-
"components",
|
|
39
|
-
"react"
|
|
40
|
-
],
|
|
41
|
-
"author": "Insforge",
|
|
42
|
-
"license": "MIT",
|
|
43
|
-
"dependencies": {
|
|
44
|
-
"@insforge/react": "^0.6.
|
|
45
|
-
"@insforge/sdk": "^0.0.58",
|
|
46
|
-
"@insforge/shared
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
"@types/react": "^19.2.2",
|
|
51
|
-
"@types/react-dom": "^19.2.2"
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
"
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@insforge/nextjs",
|
|
3
|
+
"version": "0.10.4",
|
|
4
|
+
"description": "Pre-built authentication UI components for Next.js with Insforge backend - zero configuration required",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/esm/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./middleware": {
|
|
13
|
+
"types": "./dist/middleware/index.d.ts",
|
|
14
|
+
"import": "./dist/esm/middleware/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./api": {
|
|
17
|
+
"types": "./dist/api/index.d.ts",
|
|
18
|
+
"import": "./dist/esm/api/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./styles.css": "./src/styles.css"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"src/styles.css",
|
|
25
|
+
"README.md"
|
|
26
|
+
],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsup",
|
|
29
|
+
"dev": "tsup --watch",
|
|
30
|
+
"type-check": "tsc --noEmit"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"insforge",
|
|
34
|
+
"nextjs",
|
|
35
|
+
"authentication",
|
|
36
|
+
"auth",
|
|
37
|
+
"ui",
|
|
38
|
+
"components",
|
|
39
|
+
"react"
|
|
40
|
+
],
|
|
41
|
+
"author": "Insforge",
|
|
42
|
+
"license": "MIT",
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@insforge/react": "^0.6.1",
|
|
45
|
+
"@insforge/sdk": "^0.0.58",
|
|
46
|
+
"@insforge/shared": "^0.1.0",
|
|
47
|
+
"@insforge/shared-schemas": "^1.1.19"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@types/react": "^19.2.2",
|
|
51
|
+
"@types/react-dom": "^19.2.2"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"next": "^15.0.0",
|
|
55
|
+
"react": "^19.0.0",
|
|
56
|
+
"react-dom": "^19.0.0"
|
|
57
|
+
}
|
|
58
|
+
}
|
package/src/styles.css
CHANGED