@insforge/nextjs 1.0.8-dev.2 → 1.1.0
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 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components.server.ts"],"sourcesContent":["// Server Component exports (react-server environment)\
|
|
1
|
+
{"version":3,"sources":["../../src/components.server.ts"],"sourcesContent":["// Server Component exports (react-server environment)\n// This file is used when code runs in a Server Component\n\n// Server-only utilities that use next/headers\nexport { auth, type InsforgeAuth } from './server/auth';\nexport { getAuthFromCookies } from './server/InsforgeProvider';\n\n// Server Provider (deprecated but exported for backward compatibility)\nexport {\n InsforgeServerProvider,\n type InsforgeServerProviderProps,\n type InsforgeProviderServerProps,\n} from './server/InsforgeProvider';\n"],"mappings":"AAIA,SAAS,YAA+B;AACxC,SAAS,0BAA0B;AAGnC;AAAA,EACE;AAAA,OAGK;","names":[]}
|
package/dist/esm/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
{
|
|
2
|
-
"sideEffects": false,
|
|
3
|
-
"imports": {
|
|
4
|
-
"#components": {
|
|
5
|
-
"react-server": "./components.server.js",
|
|
6
|
-
"default": "./components.client.js"
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"sideEffects": false,
|
|
3
|
+
"imports": {
|
|
4
|
+
"#components": {
|
|
5
|
+
"react-server": "./components.server.js",
|
|
6
|
+
"default": "./components.client.js"
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -35,7 +35,7 @@ async function getAuthFromCookies() {
|
|
|
35
35
|
}
|
|
36
36
|
async function InsforgeServerProvider(props) {
|
|
37
37
|
const { children, dynamic = true, baseUrl, anonKey, ...restProps } = props;
|
|
38
|
-
if (
|
|
38
|
+
if (baseUrl || anonKey) {
|
|
39
39
|
console.warn(
|
|
40
40
|
'[Insforge] \u26A0\uFE0F InsforgeServerProvider is deprecated and will not work correctly.\nSDK client instances cannot be passed from Server to Client Components in Next.js.\n\nPlease migrate to InsforgeBrowserProvider:\n1. Create a client component (e.g., app/providers.tsx) with "use client"\n2. Use InsforgeBrowserProvider with your SDK client in that component\n3. Use getAuthFromCookies() in your layout to pass initialState\n\nSee: https://insforge.com/docs/nextjs/migration'
|
|
41
41
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/server/InsforgeProvider.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\nimport { InsforgeBrowserProvider } from '../client/provider';\nimport type { InsforgeProviderProps, InitialAuthState } from '@insforge/react';\nimport { cookies } from 'next/headers';\nimport { COOKIE_NAMES, parseUserCookie } from '../lib/cookies';\n\nexport interface InsforgeServerProviderProps extends Omit<InsforgeProviderProps, 'initialState'> {\n children: ReactNode;\n /**\n * The base URL of your InsForge backend.\n *\n * @deprecated Use `InsforgeBrowserProvider` in a client component instead.\n * This prop is kept for backward compatibility only.\n */\n baseUrl?: string;\n /**\n * The anonymous key for your InsForge backend.\n *\n * @deprecated Use `InsforgeBrowserProvider` in a client component instead.\n * This prop is kept for backward compatibility only.\n */\n anonKey?: string;\n /**\n * Opt into dynamic rendering to read auth state from cookies during SSR.\n *\n * - When true: Reads cookies on server, prevents content flashing, opts into dynamic rendering\n * - When false: Static rendering, may see brief content flash during hydration\n *\n * @default true\n */\n dynamic?: boolean;\n}\n\n/**\n * @deprecated Use `InsforgeServerProviderProps` instead.\n */\nexport type InsforgeProviderServerProps = InsforgeServerProviderProps;\n\n/**\n * Get initial auth state from cookies (server-side)\n *\n * This helper reads the authentication state from cookies set by the SDK.\n * Use this in Server Components to get the initial auth state and pass it\n * to `InsforgeBrowserProvider` via the `initialState` prop.\n *\n * This prevents hydration mismatches by ensuring SSR and client render have the same state.\n *\n * @example\n * ```tsx\n * // app/layout.tsx (Server Component)\n * import { getAuthFromCookies } from '@insforge/nextjs';\n * import { Providers } from './providers';\n *\n * export default async function RootLayout({ children }) {\n * const initialState = await getAuthFromCookies();\n *\n * return (\n * <html>\n * <body>\n * <Providers initialState={initialState}>\n * {children}\n * </Providers>\n * </body>\n * </html>\n * );\n * }\n * ```\n *\n * @returns Initial auth state with user and userId, or null values if not authenticated\n */\nexport async function getAuthFromCookies(): Promise<InitialAuthState> {\n try {\n const cookieStore = await cookies();\n\n // Read session token from cookie (set by middleware or /api/auth route)\n const token = cookieStore.get(COOKIE_NAMES.SESSION)?.value || null;\n\n if (!token) {\n // Not authenticated - return null to indicate signed out\n return {\n user: null,\n userId: null,\n };\n }\n\n // Read user identity from cookie (set by middleware or /api/auth route)\n const userCookie = cookieStore.get(COOKIE_NAMES.USER)?.value;\n\n try {\n const user = parseUserCookie(userCookie);\n\n // Return basic user info from cookie\n // This is lightweight data for SSR hydration only\n // Full profile will be loaded by SDK's getCurrentUser() after hydration\n return {\n user,\n userId: user?.id || null,\n };\n } catch {\n // Invalid user data in cookie\n return {\n user: null,\n userId: null,\n };\n }\n } catch (error) {\n // Error reading cookies (might be in middleware or edge runtime)\n console.error('[Insforge] Error reading cookies:', error);\n return {\n user: null,\n userId: null,\n };\n }\n}\n\n/**\n * @deprecated **This component is deprecated.** Use `InsforgeBrowserProvider` instead.\n *\n * This Server Component wrapper doesn't work correctly because SDK client instances\n * (class objects) cannot be serialized and passed from Server to Client Components.\n *\n * ---\n *\n * ## Migration Guide\n *\n * ### Before (deprecated):\n * ```tsx\n * // app/layout.tsx\n * import { InsforgeServerProvider } from '@insforge/nextjs';\n * import { insforge } from '@/lib/insforge';\n *\n * export default function RootLayout({ children }) {\n * return (\n * <InsforgeServerProvider client={insforge}> // ❌ This fails!\n * {children}\n * </InsforgeServerProvider>\n * );\n * }\n * ```\n *\n * ### After (recommended):\n *\n * **Step 1:** Create a client-side Providers component:\n * ```tsx\n * // app/providers.tsx\n * 'use client';\n * import { InsforgeBrowserProvider, type InitialAuthState } from '@insforge/nextjs';\n * import { insforge } from '@/lib/insforge';\n *\n * export function Providers({\n * children,\n * initialState,\n * }: {\n * children: React.ReactNode;\n * initialState?: InitialAuthState;\n * }) {\n * return (\n * <InsforgeBrowserProvider client={insforge} initialState={initialState}>\n * {children}\n * </InsforgeBrowserProvider>\n * );\n * }\n * ```\n *\n * **Step 2:** Use it in your layout:\n * ```tsx\n * // app/layout.tsx\n * import { getAuthFromCookies } from '@insforge/nextjs';\n * import { Providers } from './providers';\n *\n * export default async function RootLayout({ children }) {\n * const initialState = await getAuthFromCookies();\n *\n * return (\n * <html>\n * <body>\n * <Providers initialState={initialState}>\n * {children}\n * </Providers>\n * </body>\n * </html>\n * );\n * }\n * ```\n *\n * ---\n *\n * @see InsforgeBrowserProvider - The recommended client-side provider\n * @see getAuthFromCookies - Helper to get initial auth state for SSR\n */\nexport async function InsforgeServerProvider(\n props: InsforgeServerProviderProps\n): Promise<React.JSX.Element> {\n const { children, dynamic = true, baseUrl, anonKey, ...restProps } = props;\n\n
|
|
1
|
+
{"version":3,"sources":["../../../src/server/InsforgeProvider.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\nimport { InsforgeBrowserProvider } from '../client/provider';\nimport type { InsforgeProviderProps, InitialAuthState } from '@insforge/react';\nimport { cookies } from 'next/headers';\nimport { COOKIE_NAMES, parseUserCookie } from '../lib/cookies';\n\nexport interface InsforgeServerProviderProps extends Omit<InsforgeProviderProps, 'initialState'> {\n children: ReactNode;\n /**\n * The base URL of your InsForge backend.\n *\n * @deprecated Use `InsforgeBrowserProvider` in a client component instead.\n * This prop is kept for backward compatibility only.\n */\n baseUrl?: string;\n /**\n * The anonymous key for your InsForge backend.\n *\n * @deprecated Use `InsforgeBrowserProvider` in a client component instead.\n * This prop is kept for backward compatibility only.\n */\n anonKey?: string;\n /**\n * Opt into dynamic rendering to read auth state from cookies during SSR.\n *\n * - When true: Reads cookies on server, prevents content flashing, opts into dynamic rendering\n * - When false: Static rendering, may see brief content flash during hydration\n *\n * @default true\n */\n dynamic?: boolean;\n}\n\n/**\n * @deprecated Use `InsforgeServerProviderProps` instead.\n */\nexport type InsforgeProviderServerProps = InsforgeServerProviderProps;\n\n/**\n * Get initial auth state from cookies (server-side)\n *\n * This helper reads the authentication state from cookies set by the SDK.\n * Use this in Server Components to get the initial auth state and pass it\n * to `InsforgeBrowserProvider` via the `initialState` prop.\n *\n * This prevents hydration mismatches by ensuring SSR and client render have the same state.\n *\n * @example\n * ```tsx\n * // app/layout.tsx (Server Component)\n * import { getAuthFromCookies } from '@insforge/nextjs';\n * import { Providers } from './providers';\n *\n * export default async function RootLayout({ children }) {\n * const initialState = await getAuthFromCookies();\n *\n * return (\n * <html>\n * <body>\n * <Providers initialState={initialState}>\n * {children}\n * </Providers>\n * </body>\n * </html>\n * );\n * }\n * ```\n *\n * @returns Initial auth state with user and userId, or null values if not authenticated\n */\nexport async function getAuthFromCookies(): Promise<InitialAuthState> {\n try {\n const cookieStore = await cookies();\n\n // Read session token from cookie (set by middleware or /api/auth route)\n const token = cookieStore.get(COOKIE_NAMES.SESSION)?.value || null;\n\n if (!token) {\n // Not authenticated - return null to indicate signed out\n return {\n user: null,\n userId: null,\n };\n }\n\n // Read user identity from cookie (set by middleware or /api/auth route)\n const userCookie = cookieStore.get(COOKIE_NAMES.USER)?.value;\n\n try {\n const user = parseUserCookie(userCookie);\n\n // Return basic user info from cookie\n // This is lightweight data for SSR hydration only\n // Full profile will be loaded by SDK's getCurrentUser() after hydration\n return {\n user,\n userId: user?.id || null,\n };\n } catch {\n // Invalid user data in cookie\n return {\n user: null,\n userId: null,\n };\n }\n } catch (error) {\n // Error reading cookies (might be in middleware or edge runtime)\n console.error('[Insforge] Error reading cookies:', error);\n return {\n user: null,\n userId: null,\n };\n }\n}\n\n/**\n * @deprecated **This component is deprecated.** Use `InsforgeBrowserProvider` instead.\n *\n * This Server Component wrapper doesn't work correctly because SDK client instances\n * (class objects) cannot be serialized and passed from Server to Client Components.\n *\n * ---\n *\n * ## Migration Guide\n *\n * ### Before (deprecated):\n * ```tsx\n * // app/layout.tsx\n * import { InsforgeServerProvider } from '@insforge/nextjs';\n * import { insforge } from '@/lib/insforge';\n *\n * export default function RootLayout({ children }) {\n * return (\n * <InsforgeServerProvider client={insforge}> // ❌ This fails!\n * {children}\n * </InsforgeServerProvider>\n * );\n * }\n * ```\n *\n * ### After (recommended):\n *\n * **Step 1:** Create a client-side Providers component:\n * ```tsx\n * // app/providers.tsx\n * 'use client';\n * import { InsforgeBrowserProvider, type InitialAuthState } from '@insforge/nextjs';\n * import { insforge } from '@/lib/insforge';\n *\n * export function Providers({\n * children,\n * initialState,\n * }: {\n * children: React.ReactNode;\n * initialState?: InitialAuthState;\n * }) {\n * return (\n * <InsforgeBrowserProvider client={insforge} initialState={initialState}>\n * {children}\n * </InsforgeBrowserProvider>\n * );\n * }\n * ```\n *\n * **Step 2:** Use it in your layout:\n * ```tsx\n * // app/layout.tsx\n * import { getAuthFromCookies } from '@insforge/nextjs';\n * import { Providers } from './providers';\n *\n * export default async function RootLayout({ children }) {\n * const initialState = await getAuthFromCookies();\n *\n * return (\n * <html>\n * <body>\n * <Providers initialState={initialState}>\n * {children}\n * </Providers>\n * </body>\n * </html>\n * );\n * }\n * ```\n *\n * ---\n *\n * @see InsforgeBrowserProvider - The recommended client-side provider\n * @see getAuthFromCookies - Helper to get initial auth state for SSR\n */\nexport async function InsforgeServerProvider(\n props: InsforgeServerProviderProps\n): Promise<React.JSX.Element> {\n const { children, dynamic = true, baseUrl, anonKey, ...restProps } = props;\n\n if (baseUrl || anonKey) {\n console.warn(\n '[Insforge] ⚠️ InsforgeServerProvider is deprecated and will not work correctly.\\n' +\n 'SDK client instances cannot be passed from Server to Client Components in Next.js.\\n\\n' +\n 'Please migrate to InsforgeBrowserProvider:\\n' +\n '1. Create a client component (e.g., app/providers.tsx) with \"use client\"\\n' +\n '2. Use InsforgeBrowserProvider with your SDK client in that component\\n' +\n '3. Use getAuthFromCookies() in your layout to pass initialState\\n\\n' +\n 'See: https://insforge.com/docs/nextjs/migration'\n );\n }\n\n // Only read cookies if dynamic=true (opts into dynamic rendering)\n // When dynamic=false, Next.js can statically generate the page\n const initialAuth = dynamic ? await getAuthFromCookies() : { user: null, userId: null };\n\n // Note: This will fail at runtime because `client` is a class instance\n // We still attempt to render for backward compatibility, but it won't work\n return (\n <InsforgeBrowserProvider initialState={initialAuth} {...restProps}>\n {children}\n </InsforgeBrowserProvider>\n );\n}\n\n/**\n * @deprecated Use `InsforgeServerProvider` instead (which is also deprecated).\n * Migrate to `InsforgeBrowserProvider` for proper Next.js App Router support.\n */\nexport const InsforgeProvider = InsforgeServerProvider;\n"],"mappings":"AAsNI;AArNJ,SAAS,+BAA+B;AAExC,SAAS,eAAe;AACxB,SAAS,cAAc,uBAAuB;AAkE9C,eAAsB,qBAAgD;AACpE,MAAI;AACF,UAAM,cAAc,MAAM,QAAQ;AAGlC,UAAM,QAAQ,YAAY,IAAI,aAAa,OAAO,GAAG,SAAS;AAE9D,QAAI,CAAC,OAAO;AAEV,aAAO;AAAA,QACL,MAAM;AAAA,QACN,QAAQ;AAAA,MACV;AAAA,IACF;AAGA,UAAM,aAAa,YAAY,IAAI,aAAa,IAAI,GAAG;AAEvD,QAAI;AACF,YAAM,OAAO,gBAAgB,UAAU;AAKvC,aAAO;AAAA,QACL;AAAA,QACA,QAAQ,MAAM,MAAM;AAAA,MACtB;AAAA,IACF,QAAQ;AAEN,aAAO;AAAA,QACL,MAAM;AAAA,QACN,QAAQ;AAAA,MACV;AAAA,IACF;AAAA,EACF,SAAS,OAAO;AAEd,YAAQ,MAAM,qCAAqC,KAAK;AACxD,WAAO;AAAA,MACL,MAAM;AAAA,MACN,QAAQ;AAAA,IACV;AAAA,EACF;AACF;AA6EA,eAAsB,uBACpB,OAC4B;AAC5B,QAAM,EAAE,UAAU,UAAU,MAAM,SAAS,SAAS,GAAG,UAAU,IAAI;AAErE,MAAI,WAAW,SAAS;AACtB,YAAQ;AAAA,MACN;AAAA,IAOF;AAAA,EACF;AAIA,QAAM,cAAc,UAAU,MAAM,mBAAmB,IAAI,EAAE,MAAM,MAAM,QAAQ,KAAK;AAItF,SACE,oBAAC,2BAAwB,cAAc,aAAc,GAAG,WACrD,UACH;AAEJ;AAMO,MAAM,mBAAmB;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@insforge/nextjs",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Pre-built authentication UI components for Next.js with Insforge backend - zero configuration required",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -45,9 +45,9 @@
|
|
|
45
45
|
"author": "Insforge",
|
|
46
46
|
"license": "MIT",
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@insforge/react": "1.0
|
|
49
|
-
"@insforge/sdk": "1.0.
|
|
50
|
-
"@insforge/shared": "1.0
|
|
48
|
+
"@insforge/react": "1.1.0",
|
|
49
|
+
"@insforge/sdk": "1.0.8",
|
|
50
|
+
"@insforge/shared": "1.1.0",
|
|
51
51
|
"@insforge/shared-schemas": "^1.1.35"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|