@insforge/sdk 1.2.10 → 1.3.0-ssr.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.
- package/README.md +60 -14
- package/dist/client-B8ykVESe.d.mts +1121 -0
- package/dist/client-B8ykVESe.d.ts +1121 -0
- package/dist/index.d.mts +4 -1113
- package/dist/index.d.ts +4 -1113
- package/dist/index.js +22 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +23 -7
- package/dist/index.mjs.map +1 -1
- package/dist/ssr.d.mts +88 -0
- package/dist/ssr.d.ts +88 -0
- package/dist/ssr.js +3219 -0
- package/dist/ssr.js.map +1 -0
- package/dist/ssr.mjs +3180 -0
- package/dist/ssr.mjs.map +1 -0
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -258,28 +258,74 @@ The SDK supports the following configuration options:
|
|
|
258
258
|
const insforge = createClient({
|
|
259
259
|
baseUrl: "http://localhost:7130", // Your InsForge backend URL
|
|
260
260
|
anonKey: "your-anon-key", // Optional
|
|
261
|
-
isServerMode: false, // Optional (set true in SSR/server runtime)
|
|
262
261
|
});
|
|
263
262
|
```
|
|
264
263
|
|
|
265
264
|
### SSR / Next.js
|
|
266
265
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
266
|
+
Use `@insforge/sdk/ssr` for apps that need the same auth session in Server Components, Client Components, Storage, and Realtime.
|
|
267
|
+
The helper uses explicit `baseUrl` / `anonKey` when provided. Otherwise it reads `NEXT_PUBLIC_INSFORGE_URL` / `NEXT_PUBLIC_INSFORGE_ANON_KEY`. Missing config throws a clear error.
|
|
268
|
+
|
|
269
|
+
By default, the SSR helpers use:
|
|
270
|
+
|
|
271
|
+
- `insforge_access_token`: browser-readable access token cookie, expires at the JWT `exp`
|
|
272
|
+
- `insforge_refresh_token`: httpOnly refresh token cookie, expires at the JWT `exp`
|
|
273
273
|
|
|
274
274
|
```typescript
|
|
275
|
-
|
|
276
|
-
|
|
275
|
+
// app/lib/insforge/client.ts
|
|
276
|
+
import { createBrowserClient } from "@insforge/sdk/ssr";
|
|
277
277
|
|
|
278
|
-
const insforge =
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
278
|
+
export const insforge = createBrowserClient();
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
```typescript
|
|
282
|
+
// app/lib/insforge/server.ts
|
|
283
|
+
import { cookies } from "next/headers";
|
|
284
|
+
import { createServerClient } from "@insforge/sdk/ssr";
|
|
285
|
+
|
|
286
|
+
export async function createInsForgeServerClient() {
|
|
287
|
+
return createServerClient({ cookies: await cookies() });
|
|
288
|
+
}
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
```typescript
|
|
292
|
+
// app/api/auth/refresh/route.ts
|
|
293
|
+
import { createRefreshAuthRouter } from "@insforge/sdk/ssr";
|
|
294
|
+
|
|
295
|
+
export const { POST } = createRefreshAuthRouter();
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
For server-owned refresh cookies, run sign-in in a Route Handler or Server Action and use `setAuthCookies()` from `@insforge/sdk/ssr` with the auth response.
|
|
299
|
+
|
|
300
|
+
If your refresh route needs custom side effects:
|
|
301
|
+
|
|
302
|
+
```typescript
|
|
303
|
+
import { refreshAuth } from "@insforge/sdk/ssr";
|
|
304
|
+
|
|
305
|
+
export async function POST(request: Request) {
|
|
306
|
+
const result = await refreshAuth({ request });
|
|
307
|
+
// run app-specific side effects here
|
|
308
|
+
return result.response;
|
|
309
|
+
}
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
For Next.js Proxy/Middleware, refresh before Server Components render:
|
|
313
|
+
|
|
314
|
+
```typescript
|
|
315
|
+
// proxy.ts on Next.js 16+, middleware.ts on Next.js 15 and earlier
|
|
316
|
+
import { NextResponse, type NextRequest } from "next/server";
|
|
317
|
+
import { updateSession } from "@insforge/sdk/ssr";
|
|
318
|
+
|
|
319
|
+
export async function proxy(request: NextRequest) {
|
|
320
|
+
const response = NextResponse.next({ request });
|
|
321
|
+
|
|
322
|
+
await updateSession({
|
|
323
|
+
requestCookies: request.cookies,
|
|
324
|
+
responseCookies: response.cookies,
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
return response;
|
|
328
|
+
}
|
|
283
329
|
```
|
|
284
330
|
|
|
285
331
|
## TypeScript Support
|