@insforge/nextjs 0.10.3 → 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.
@@ -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
- declare function InsforgeMiddleware(config: InsforgeMiddlewareConfig): (request: NextRequest) => Promise<NextResponse<unknown>>;
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.3",
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.0",
45
- "@insforge/sdk": "^0.0.58",
46
- "@insforge/shared-schemas": "^1.1.19"
47
- },
48
- "devDependencies": {
49
- "@types/node": "^24.9.2",
50
- "@types/react": "^19.2.2",
51
- "@types/react-dom": "^19.2.2",
52
- "tsup": "^8.5.0",
53
- "typescript": "^5.9.3"
54
- },
55
- "peerDependencies": {
56
- "next": "^15.0.0",
57
- "react": "^19.0.0",
58
- "react-dom": "^19.0.0"
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
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  /* Import base React package styles - contains all component styles */
9
- @import '@insforge/react/styles.css';
9
+ @import '@insforge/react/styles.css';