idenplane-nextjs 1.0.1

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 +159 -0
  2. package/package.json +105 -0
package/README.md ADDED
@@ -0,0 +1,159 @@
1
+ # idenplane-nextjs
2
+
3
+ Next.js SDK for [Idenplane](https://github.com/idenplane/idenplane) — integrates Idenplane OIDC authentication into Next.js applications with support for the App Router, Pages Router, middleware, and Server Components.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install idenplane-nextjs idenplane-sdk
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ### 1. Wrap your app with `AuthProvider`
14
+
15
+ ```tsx
16
+ // app/layout.tsx
17
+ 'use client';
18
+ import { AuthProvider } from 'idenplane-nextjs';
19
+
20
+ export default function RootLayout({ children }: { children: React.ReactNode }) {
21
+ return (
22
+ <html>
23
+ <body>
24
+ <AuthProvider
25
+ serverUrl="http://localhost:3000"
26
+ realm="my-realm"
27
+ clientId="my-app"
28
+ redirectUri="http://localhost:3001/callback"
29
+ >
30
+ {children}
31
+ </AuthProvider>
32
+ </body>
33
+ </html>
34
+ );
35
+ }
36
+ ```
37
+
38
+ ### 2. Use auth state in client components
39
+
40
+ ```tsx
41
+ 'use client';
42
+ import { useAuth } from 'idenplane-nextjs';
43
+
44
+ export function NavBar() {
45
+ const { isAuthenticated, user, login, logout, isLoading } = useAuth();
46
+
47
+ if (isLoading) return <span>Loading...</span>;
48
+ if (!isAuthenticated) return <button onClick={() => login()}>Sign In</button>;
49
+ return (
50
+ <div>
51
+ <span>{user?.name}</span>
52
+ <button onClick={logout}>Sign Out</button>
53
+ </div>
54
+ );
55
+ }
56
+ ```
57
+
58
+ ### 3. Protect routes with middleware
59
+
60
+ ```typescript
61
+ // middleware.ts
62
+ import { NextResponse } from 'next/server';
63
+ import type { NextRequest } from 'next/server';
64
+ import { createAuthMiddleware } from 'idenplane-nextjs/middleware';
65
+
66
+ const authMiddleware = createAuthMiddleware({
67
+ serverUrl: 'http://localhost:3000',
68
+ realm: 'my-realm',
69
+ clientId: 'my-app',
70
+ protectedPaths: ['/dashboard', '/api/protected'],
71
+ loginPath: '/login',
72
+ });
73
+
74
+ export default function middleware(request: NextRequest) {
75
+ return authMiddleware(request as never, NextResponse as never);
76
+ }
77
+
78
+ export const config = {
79
+ matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
80
+ };
81
+ ```
82
+
83
+ ### 4. Server Components
84
+
85
+ ```tsx
86
+ // app/dashboard/page.tsx
87
+ import { cookies } from 'next/headers';
88
+ import { getServerUser } from 'idenplane-nextjs/server';
89
+ import { redirect } from 'next/navigation';
90
+
91
+ export default async function DashboardPage() {
92
+ const cookieStore = cookies();
93
+ const user = await getServerUser(cookieStore, {
94
+ serverUrl: 'http://localhost:3000',
95
+ realm: 'my-realm',
96
+ });
97
+
98
+ if (!user) redirect('/login');
99
+
100
+ return <h1>Hello, {user.name}!</h1>;
101
+ }
102
+ ```
103
+
104
+ ### 5. API Routes (Pages Router)
105
+
106
+ ```typescript
107
+ // pages/api/profile.ts
108
+ import { withAuth } from 'idenplane-nextjs/api';
109
+
110
+ export default withAuth(
111
+ { serverUrl: 'http://localhost:3000', realm: 'my-realm' },
112
+ (req, res) => {
113
+ res.json({ user: req.authUser });
114
+ },
115
+ );
116
+ ```
117
+
118
+ ### 5b. Route Handlers (App Router)
119
+
120
+ ```typescript
121
+ // app/api/profile/route.ts
122
+ import { withAuthHandler } from 'idenplane-nextjs/api';
123
+
124
+ export const GET = withAuthHandler(
125
+ { serverUrl: 'http://localhost:3000', realm: 'my-realm' },
126
+ (_req, user) => Response.json({ user }),
127
+ );
128
+ ```
129
+
130
+ ## API Reference
131
+
132
+ ### `idenplane-nextjs` (default export)
133
+
134
+ Re-exports from `idenplane-sdk/react`:
135
+
136
+ - `AuthProvider` / `IdenplaneProvider` — context provider
137
+ - `useAuth()` — authentication state and actions
138
+ - `useUser()` — current user info
139
+ - `usePermissions()` — role and permission helpers
140
+ - `ProtectedRoute` — render-gate component
141
+ - `IdenplaneClient` — raw client class
142
+
143
+ ### `idenplane-nextjs/middleware`
144
+
145
+ - `createAuthMiddleware(config)` — Next.js Edge middleware factory
146
+
147
+ ### `idenplane-nextjs/server`
148
+
149
+ - `getServerAuth(cookies, config?)` — returns `AuthSession | null`
150
+ - `getServerUser(cookies, config?)` — returns `User | null`
151
+
152
+ ### `idenplane-nextjs/api`
153
+
154
+ - `withAuth(config, handler)` — Pages Router API handler wrapper
155
+ - `withAuthHandler(config, handler)` — App Router Route Handler wrapper
156
+
157
+ ## License
158
+
159
+ MIT
package/package.json ADDED
@@ -0,0 +1,105 @@
1
+ {
2
+ "name": "idenplane-nextjs",
3
+ "version": "1.0.1",
4
+ "description": "Next.js SDK for Idenplane Identity and Access Management Server",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/index.cjs"
18
+ }
19
+ },
20
+ "./middleware": {
21
+ "import": {
22
+ "types": "./dist/middleware.d.ts",
23
+ "default": "./dist/middleware.js"
24
+ },
25
+ "require": {
26
+ "types": "./dist/middleware.d.cts",
27
+ "default": "./dist/middleware.cjs"
28
+ }
29
+ },
30
+ "./server": {
31
+ "import": {
32
+ "types": "./dist/server.d.ts",
33
+ "default": "./dist/server.js"
34
+ },
35
+ "require": {
36
+ "types": "./dist/server.d.cts",
37
+ "default": "./dist/server.cjs"
38
+ }
39
+ },
40
+ "./api": {
41
+ "import": {
42
+ "types": "./dist/api.d.ts",
43
+ "default": "./dist/api.js"
44
+ },
45
+ "require": {
46
+ "types": "./dist/api.d.cts",
47
+ "default": "./dist/api.cjs"
48
+ }
49
+ }
50
+ },
51
+ "peerDependencies": {
52
+ "idenplane-sdk": ">=1.0.0",
53
+ "next": ">=13.0.0",
54
+ "react": ">=18.0.0"
55
+ },
56
+ "peerDependenciesMeta": {
57
+ "next": {
58
+ "optional": false
59
+ },
60
+ "react": {
61
+ "optional": false
62
+ }
63
+ },
64
+ "scripts": {
65
+ "build": "tsup",
66
+ "dev": "tsup --watch",
67
+ "typecheck": "tsc --noEmit",
68
+ "test": "vitest run",
69
+ "test:watch": "vitest"
70
+ },
71
+ "devDependencies": {
72
+ "@types/react": "^19.0.0",
73
+ "idenplane-sdk": "file:../idenplane-js",
74
+ "next": "^15.0.0",
75
+ "react": "^19.0.0",
76
+ "tsup": "^8.4.0",
77
+ "typescript": "^5.7.0",
78
+ "vitest": "^4.0.18"
79
+ },
80
+ "overrides": {
81
+ "postcss": "^8.5.10",
82
+ "esbuild": ">=0.28.1"
83
+ },
84
+ "files": [
85
+ "dist",
86
+ "README.md"
87
+ ],
88
+ "keywords": [
89
+ "idenplane",
90
+ "oauth2",
91
+ "oidc",
92
+ "nextjs",
93
+ "authentication",
94
+ "middleware"
95
+ ],
96
+ "license": "MIT",
97
+ "repository": {
98
+ "type": "git",
99
+ "url": "https://github.com/idenplane/idenplane.git",
100
+ "directory": "packages/idenplane-nextjs"
101
+ },
102
+ "publishConfig": {
103
+ "access": "public"
104
+ }
105
+ }