@insforge/react 0.4.12 → 0.5.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.
@@ -0,0 +1,53 @@
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+ var jsxRuntime = require('react/jsx-runtime');
5
+
6
+ // src/navigation/NavigationContext.tsx
7
+ var NavigationContext = react.createContext(null);
8
+ function NavigationProvider({ adapter, children }) {
9
+ return /* @__PURE__ */ jsxRuntime.jsx(NavigationContext.Provider, { value: adapter, children });
10
+ }
11
+ function useNavigationAdapter() {
12
+ const adapter = react.useContext(NavigationContext);
13
+ if (!adapter) {
14
+ throw new Error("useNavigationAdapter must be used within NavigationProvider");
15
+ }
16
+ return adapter;
17
+ }
18
+ var BrowserNavigationAdapter = {
19
+ /**
20
+ * Returns URLSearchParams from current window.location.search
21
+ * Note: Not reactive - reads once on component mount
22
+ * This is sufficient for auth flows where we read initial URL params
23
+ */
24
+ useSearchParams() {
25
+ const [searchParams] = react.useState(() => {
26
+ if (typeof window === "undefined") {
27
+ return new URLSearchParams();
28
+ }
29
+ return new URLSearchParams(window.location.search);
30
+ });
31
+ return searchParams;
32
+ },
33
+ /**
34
+ * Native <a> tag for navigation
35
+ * Uses full page reload
36
+ */
37
+ Link({ href, className, children }) {
38
+ return /* @__PURE__ */ jsxRuntime.jsx("a", { href, className, children });
39
+ }
40
+ };
41
+
42
+ // src/navigation/useSearchParams.ts
43
+ function useSearchParams() {
44
+ const adapter = useNavigationAdapter();
45
+ return adapter.useSearchParams();
46
+ }
47
+
48
+ exports.BrowserNavigationAdapter = BrowserNavigationAdapter;
49
+ exports.NavigationProvider = NavigationProvider;
50
+ exports.useNavigationAdapter = useNavigationAdapter;
51
+ exports.useSearchParams = useSearchParams;
52
+ //# sourceMappingURL=navigation.cjs.map
53
+ //# sourceMappingURL=navigation.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/navigation/NavigationContext.tsx","../src/navigation/BrowserNavigationAdapter.tsx","../src/navigation/useSearchParams.ts"],"names":["createContext","useContext","useState","jsx"],"mappings":";;;;;;AAGA,IAAM,iBAAA,GAAoBA,oBAAwC,IAAI,CAAA;AAW/D,SAAS,kBAAA,CAAmB,EAAE,OAAA,EAAS,QAAA,EAAS,EAA4B;AACjF,EAAA,sCAAQ,iBAAA,CAAkB,QAAA,EAAlB,EAA2B,KAAA,EAAO,SAAU,QAAA,EAAS,CAAA;AAC/D;AAMO,SAAS,oBAAA,GAA0C;AACxD,EAAA,MAAM,OAAA,GAAUC,iBAAW,iBAAiB,CAAA;AAE5C,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,IAAI,MAAM,6DAA6D,CAAA;AAAA,EAC/E;AAEA,EAAA,OAAO,OAAA;AACT;ACtBO,IAAM,wBAAA,GAA8C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMzD,eAAA,GAAkB;AAChB,IAAA,MAAM,CAAC,YAAY,CAAA,GAAIC,cAAA,CAAS,MAAM;AACpC,MAAA,IAAI,OAAO,WAAW,WAAA,EAAa;AACjC,QAAA,OAAO,IAAI,eAAA,EAAgB;AAAA,MAC7B;AACA,MAAA,OAAO,IAAI,eAAA,CAAgB,MAAA,CAAO,QAAA,CAAS,MAAM,CAAA;AAAA,IACnD,CAAC,CAAA;AAED,IAAA,OAAO,YAAA;AAAA,EACT,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAA,CAAK,EAAE,IAAA,EAAM,SAAA,EAAW,UAAS,EAAG;AAClC,IAAA,uBACEC,cAAAA,CAAC,GAAA,EAAA,EAAE,IAAA,EAAY,WACZ,QAAA,EACH,CAAA;AAAA,EAEJ;AACF;;;ACnBO,SAAS,eAAA,GAAmC;AACjD,EAAA,MAAM,UAAU,oBAAA,EAAqB;AACrC,EAAA,OAAO,QAAQ,eAAA,EAAgB;AACjC","file":"navigation.cjs","sourcesContent":["import { createContext, useContext, ReactNode } from 'react';\nimport type { NavigationAdapter } from './types';\n\nconst NavigationContext = createContext<NavigationAdapter | null>(null);\n\nexport interface NavigationProviderProps {\n adapter: NavigationAdapter;\n children: ReactNode;\n}\n\n/**\n * Navigation Provider\n * Injects navigation adapter into the component tree\n */\nexport function NavigationProvider({ adapter, children }: NavigationProviderProps) {\n return <NavigationContext.Provider value={adapter}>{children}</NavigationContext.Provider>;\n}\n\n/**\n * Hook to access navigation adapter\n * @throws Error if used outside NavigationProvider\n */\nexport function useNavigationAdapter(): NavigationAdapter {\n const adapter = useContext(NavigationContext);\n\n if (!adapter) {\n throw new Error('useNavigationAdapter must be used within NavigationProvider');\n }\n\n return adapter;\n}\n","import { useState } from 'react';\nimport type { NavigationAdapter } from './types';\n\n/**\n * Browser native navigation adapter\n * Uses browser's native URLSearchParams and <a> tags\n * Suitable for vanilla React apps without a routing library\n */\nexport const BrowserNavigationAdapter: NavigationAdapter = {\n /**\n * Returns URLSearchParams from current window.location.search\n * Note: Not reactive - reads once on component mount\n * This is sufficient for auth flows where we read initial URL params\n */\n useSearchParams() {\n const [searchParams] = useState(() => {\n if (typeof window === 'undefined') {\n return new URLSearchParams();\n }\n return new URLSearchParams(window.location.search);\n });\n\n return searchParams;\n },\n\n /**\n * Native <a> tag for navigation\n * Uses full page reload\n */\n Link({ href, className, children }) {\n return (\n <a href={href} className={className}>\n {children}\n </a>\n );\n },\n};\n","import { useNavigationAdapter } from './NavigationContext';\n\n/**\n * Hook to get URL search parameters\n * Uses the navigation adapter injected by NavigationProvider\n *\n * @returns URLSearchParams object\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * const searchParams = useSearchParams();\n * const redirectUrl = searchParams.get('redirect') || '/';\n * // ...\n * }\n * ```\n */\nexport function useSearchParams(): URLSearchParams {\n const adapter = useNavigationAdapter();\n return adapter.useSearchParams();\n}\n"]}
@@ -0,0 +1,64 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ComponentType, ReactNode } from 'react';
3
+
4
+ /**
5
+ * Navigation adapter interface
6
+ * Allows different routing implementations (browser, react-router, next.js)
7
+ */
8
+ interface NavigationAdapter {
9
+ /**
10
+ * Hook to get URL search parameters
11
+ * Returns URLSearchParams for consistent API across adapters
12
+ */
13
+ useSearchParams(): URLSearchParams;
14
+ /**
15
+ * Link component for navigation
16
+ * Each adapter provides its own implementation (native <a>, React Router Link, Next.js Link, etc.)
17
+ */
18
+ Link: ComponentType<{
19
+ href: string;
20
+ className?: string;
21
+ children: ReactNode;
22
+ }>;
23
+ }
24
+
25
+ interface NavigationProviderProps {
26
+ adapter: NavigationAdapter;
27
+ children: ReactNode;
28
+ }
29
+ /**
30
+ * Navigation Provider
31
+ * Injects navigation adapter into the component tree
32
+ */
33
+ declare function NavigationProvider({ adapter, children }: NavigationProviderProps): react_jsx_runtime.JSX.Element;
34
+ /**
35
+ * Hook to access navigation adapter
36
+ * @throws Error if used outside NavigationProvider
37
+ */
38
+ declare function useNavigationAdapter(): NavigationAdapter;
39
+
40
+ /**
41
+ * Browser native navigation adapter
42
+ * Uses browser's native URLSearchParams and <a> tags
43
+ * Suitable for vanilla React apps without a routing library
44
+ */
45
+ declare const BrowserNavigationAdapter: NavigationAdapter;
46
+
47
+ /**
48
+ * Hook to get URL search parameters
49
+ * Uses the navigation adapter injected by NavigationProvider
50
+ *
51
+ * @returns URLSearchParams object
52
+ *
53
+ * @example
54
+ * ```tsx
55
+ * function MyComponent() {
56
+ * const searchParams = useSearchParams();
57
+ * const redirectUrl = searchParams.get('redirect') || '/';
58
+ * // ...
59
+ * }
60
+ * ```
61
+ */
62
+ declare function useSearchParams(): URLSearchParams;
63
+
64
+ export { BrowserNavigationAdapter, type NavigationAdapter, NavigationProvider, type NavigationProviderProps, useNavigationAdapter, useSearchParams };
@@ -0,0 +1,64 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ComponentType, ReactNode } from 'react';
3
+
4
+ /**
5
+ * Navigation adapter interface
6
+ * Allows different routing implementations (browser, react-router, next.js)
7
+ */
8
+ interface NavigationAdapter {
9
+ /**
10
+ * Hook to get URL search parameters
11
+ * Returns URLSearchParams for consistent API across adapters
12
+ */
13
+ useSearchParams(): URLSearchParams;
14
+ /**
15
+ * Link component for navigation
16
+ * Each adapter provides its own implementation (native <a>, React Router Link, Next.js Link, etc.)
17
+ */
18
+ Link: ComponentType<{
19
+ href: string;
20
+ className?: string;
21
+ children: ReactNode;
22
+ }>;
23
+ }
24
+
25
+ interface NavigationProviderProps {
26
+ adapter: NavigationAdapter;
27
+ children: ReactNode;
28
+ }
29
+ /**
30
+ * Navigation Provider
31
+ * Injects navigation adapter into the component tree
32
+ */
33
+ declare function NavigationProvider({ adapter, children }: NavigationProviderProps): react_jsx_runtime.JSX.Element;
34
+ /**
35
+ * Hook to access navigation adapter
36
+ * @throws Error if used outside NavigationProvider
37
+ */
38
+ declare function useNavigationAdapter(): NavigationAdapter;
39
+
40
+ /**
41
+ * Browser native navigation adapter
42
+ * Uses browser's native URLSearchParams and <a> tags
43
+ * Suitable for vanilla React apps without a routing library
44
+ */
45
+ declare const BrowserNavigationAdapter: NavigationAdapter;
46
+
47
+ /**
48
+ * Hook to get URL search parameters
49
+ * Uses the navigation adapter injected by NavigationProvider
50
+ *
51
+ * @returns URLSearchParams object
52
+ *
53
+ * @example
54
+ * ```tsx
55
+ * function MyComponent() {
56
+ * const searchParams = useSearchParams();
57
+ * const redirectUrl = searchParams.get('redirect') || '/';
58
+ * // ...
59
+ * }
60
+ * ```
61
+ */
62
+ declare function useSearchParams(): URLSearchParams;
63
+
64
+ export { BrowserNavigationAdapter, type NavigationAdapter, NavigationProvider, type NavigationProviderProps, useNavigationAdapter, useSearchParams };
@@ -0,0 +1,48 @@
1
+ import { createContext, useContext, useState } from 'react';
2
+ import { jsx } from 'react/jsx-runtime';
3
+
4
+ // src/navigation/NavigationContext.tsx
5
+ var NavigationContext = createContext(null);
6
+ function NavigationProvider({ adapter, children }) {
7
+ return /* @__PURE__ */ jsx(NavigationContext.Provider, { value: adapter, children });
8
+ }
9
+ function useNavigationAdapter() {
10
+ const adapter = useContext(NavigationContext);
11
+ if (!adapter) {
12
+ throw new Error("useNavigationAdapter must be used within NavigationProvider");
13
+ }
14
+ return adapter;
15
+ }
16
+ var BrowserNavigationAdapter = {
17
+ /**
18
+ * Returns URLSearchParams from current window.location.search
19
+ * Note: Not reactive - reads once on component mount
20
+ * This is sufficient for auth flows where we read initial URL params
21
+ */
22
+ useSearchParams() {
23
+ const [searchParams] = useState(() => {
24
+ if (typeof window === "undefined") {
25
+ return new URLSearchParams();
26
+ }
27
+ return new URLSearchParams(window.location.search);
28
+ });
29
+ return searchParams;
30
+ },
31
+ /**
32
+ * Native <a> tag for navigation
33
+ * Uses full page reload
34
+ */
35
+ Link({ href, className, children }) {
36
+ return /* @__PURE__ */ jsx("a", { href, className, children });
37
+ }
38
+ };
39
+
40
+ // src/navigation/useSearchParams.ts
41
+ function useSearchParams() {
42
+ const adapter = useNavigationAdapter();
43
+ return adapter.useSearchParams();
44
+ }
45
+
46
+ export { BrowserNavigationAdapter, NavigationProvider, useNavigationAdapter, useSearchParams };
47
+ //# sourceMappingURL=navigation.js.map
48
+ //# sourceMappingURL=navigation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/navigation/NavigationContext.tsx","../src/navigation/BrowserNavigationAdapter.tsx","../src/navigation/useSearchParams.ts"],"names":["jsx"],"mappings":";;;;AAGA,IAAM,iBAAA,GAAoB,cAAwC,IAAI,CAAA;AAW/D,SAAS,kBAAA,CAAmB,EAAE,OAAA,EAAS,QAAA,EAAS,EAA4B;AACjF,EAAA,2BAAQ,iBAAA,CAAkB,QAAA,EAAlB,EAA2B,KAAA,EAAO,SAAU,QAAA,EAAS,CAAA;AAC/D;AAMO,SAAS,oBAAA,GAA0C;AACxD,EAAA,MAAM,OAAA,GAAU,WAAW,iBAAiB,CAAA;AAE5C,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,IAAI,MAAM,6DAA6D,CAAA;AAAA,EAC/E;AAEA,EAAA,OAAO,OAAA;AACT;ACtBO,IAAM,wBAAA,GAA8C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMzD,eAAA,GAAkB;AAChB,IAAA,MAAM,CAAC,YAAY,CAAA,GAAI,QAAA,CAAS,MAAM;AACpC,MAAA,IAAI,OAAO,WAAW,WAAA,EAAa;AACjC,QAAA,OAAO,IAAI,eAAA,EAAgB;AAAA,MAC7B;AACA,MAAA,OAAO,IAAI,eAAA,CAAgB,MAAA,CAAO,QAAA,CAAS,MAAM,CAAA;AAAA,IACnD,CAAC,CAAA;AAED,IAAA,OAAO,YAAA;AAAA,EACT,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAA,CAAK,EAAE,IAAA,EAAM,SAAA,EAAW,UAAS,EAAG;AAClC,IAAA,uBACEA,GAAAA,CAAC,GAAA,EAAA,EAAE,IAAA,EAAY,WACZ,QAAA,EACH,CAAA;AAAA,EAEJ;AACF;;;ACnBO,SAAS,eAAA,GAAmC;AACjD,EAAA,MAAM,UAAU,oBAAA,EAAqB;AACrC,EAAA,OAAO,QAAQ,eAAA,EAAgB;AACjC","file":"navigation.js","sourcesContent":["import { createContext, useContext, ReactNode } from 'react';\nimport type { NavigationAdapter } from './types';\n\nconst NavigationContext = createContext<NavigationAdapter | null>(null);\n\nexport interface NavigationProviderProps {\n adapter: NavigationAdapter;\n children: ReactNode;\n}\n\n/**\n * Navigation Provider\n * Injects navigation adapter into the component tree\n */\nexport function NavigationProvider({ adapter, children }: NavigationProviderProps) {\n return <NavigationContext.Provider value={adapter}>{children}</NavigationContext.Provider>;\n}\n\n/**\n * Hook to access navigation adapter\n * @throws Error if used outside NavigationProvider\n */\nexport function useNavigationAdapter(): NavigationAdapter {\n const adapter = useContext(NavigationContext);\n\n if (!adapter) {\n throw new Error('useNavigationAdapter must be used within NavigationProvider');\n }\n\n return adapter;\n}\n","import { useState } from 'react';\nimport type { NavigationAdapter } from './types';\n\n/**\n * Browser native navigation adapter\n * Uses browser's native URLSearchParams and <a> tags\n * Suitable for vanilla React apps without a routing library\n */\nexport const BrowserNavigationAdapter: NavigationAdapter = {\n /**\n * Returns URLSearchParams from current window.location.search\n * Note: Not reactive - reads once on component mount\n * This is sufficient for auth flows where we read initial URL params\n */\n useSearchParams() {\n const [searchParams] = useState(() => {\n if (typeof window === 'undefined') {\n return new URLSearchParams();\n }\n return new URLSearchParams(window.location.search);\n });\n\n return searchParams;\n },\n\n /**\n * Native <a> tag for navigation\n * Uses full page reload\n */\n Link({ href, className, children }) {\n return (\n <a href={href} className={className}>\n {children}\n </a>\n );\n },\n};\n","import { useNavigationAdapter } from './NavigationContext';\n\n/**\n * Hook to get URL search parameters\n * Uses the navigation adapter injected by NavigationProvider\n *\n * @returns URLSearchParams object\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * const searchParams = useSearchParams();\n * const redirectUrl = searchParams.get('redirect') || '/';\n * // ...\n * }\n * ```\n */\nexport function useSearchParams(): URLSearchParams {\n const adapter = useNavigationAdapter();\n return adapter.useSearchParams();\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@insforge/react",
3
- "version": "0.4.12",
3
+ "version": "0.5.1",
4
4
  "type": "module",
5
5
  "description": "Framework-agnostic React authentication UI components for Insforge - reusable across all frameworks",
6
6
  "main": "./dist/index.cjs",
@@ -42,10 +42,10 @@
42
42
  "import": "./dist/types.js",
43
43
  "require": "./dist/types.cjs"
44
44
  },
45
- "./router": {
46
- "types": "./dist/router.d.ts",
47
- "import": "./dist/router.js",
48
- "require": "./dist/router.cjs"
45
+ "./navigation": {
46
+ "types": "./dist/navigation.d.ts",
47
+ "import": "./dist/navigation.js",
48
+ "require": "./dist/navigation.cjs"
49
49
  },
50
50
  "./provider": {
51
51
  "types": "./dist/provider.d.ts",
@@ -82,8 +82,7 @@
82
82
  "license": "MIT",
83
83
  "peerDependencies": {
84
84
  "react": "^19.0.0",
85
- "react-dom": "^19.0.0",
86
- "react-router-dom": "^7.9.5"
85
+ "react-dom": "^19.0.0"
87
86
  },
88
87
  "dependencies": {
89
88
  "@insforge/sdk": "^0.0.58-dev.15",
package/dist/router.cjs DELETED
@@ -1,45 +0,0 @@
1
- 'use strict';
2
-
3
- var react = require('react');
4
- var jsxRuntime = require('react/jsx-runtime');
5
-
6
- // src/router/getInsforgeRoutes.tsx
7
- function RedirectToAuth({
8
- baseUrl,
9
- path,
10
- afterSignInUrl
11
- }) {
12
- react.useEffect(() => {
13
- const currentUrl = window.location.origin + afterSignInUrl;
14
- const authUrl = new URL(path, baseUrl);
15
- authUrl.searchParams.set("redirect", currentUrl);
16
- window.location.replace(authUrl.toString());
17
- }, [baseUrl, path, afterSignInUrl]);
18
- return null;
19
- }
20
- function getInsforgeRoutes(config) {
21
- const { baseUrl, builtInAuth = true, paths = {}, afterSignInUrl = "/" } = config;
22
- const { signIn = "/sign-in", signUp = "/sign-up", forgotPassword = "/forgot-password" } = paths;
23
- const routes = [];
24
- if (builtInAuth) {
25
- routes.push(
26
- {
27
- path: signIn,
28
- element: /* @__PURE__ */ jsxRuntime.jsx(RedirectToAuth, { baseUrl, path: "/auth/sign-in", afterSignInUrl })
29
- },
30
- {
31
- path: signUp,
32
- element: /* @__PURE__ */ jsxRuntime.jsx(RedirectToAuth, { baseUrl, path: "/auth/sign-up", afterSignInUrl })
33
- },
34
- {
35
- path: forgotPassword,
36
- element: /* @__PURE__ */ jsxRuntime.jsx(RedirectToAuth, { baseUrl, path: "/auth/forgot-password" })
37
- }
38
- );
39
- }
40
- return routes;
41
- }
42
-
43
- exports.getInsforgeRoutes = getInsforgeRoutes;
44
- //# sourceMappingURL=router.cjs.map
45
- //# sourceMappingURL=router.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/router/getInsforgeRoutes.tsx"],"names":["useEffect","jsx"],"mappings":";;;;;;AAyCA,SAAS,cAAA,CAAe;AAAA,EACtB,OAAA;AAAA,EACA,IAAA;AAAA,EACA;AACF,CAAA,EAIG;AACD,EAAAA,eAAA,CAAU,MAAM;AAEd,IAAA,MAAM,UAAA,GAAa,MAAA,CAAO,QAAA,CAAS,MAAA,GAAS,cAAA;AAC5C,IAAA,MAAM,OAAA,GAAU,IAAI,GAAA,CAAI,IAAA,EAAM,OAAO,CAAA;AACrC,IAAA,OAAA,CAAQ,YAAA,CAAa,GAAA,CAAI,UAAA,EAAY,UAAU,CAAA;AAC/C,IAAA,MAAA,CAAO,QAAA,CAAS,OAAA,CAAQ,OAAA,CAAQ,QAAA,EAAU,CAAA;AAAA,EAC5C,CAAA,EAAG,CAAC,OAAA,EAAS,IAAA,EAAM,cAAc,CAAC,CAAA;AAElC,EAAA,OAAO,IAAA;AACT;AA6CO,SAAS,kBAAkB,MAAA,EAAgD;AAChF,EAAA,MAAM,EAAE,SAAS,WAAA,GAAc,IAAA,EAAM,QAAQ,EAAC,EAAG,cAAA,GAAiB,GAAA,EAAI,GAAI,MAAA;AAE1E,EAAA,MAAM,EAAE,MAAA,GAAS,UAAA,EAAY,SAAS,UAAA,EAAY,cAAA,GAAiB,oBAAmB,GAAI,KAAA;AAE1F,EAAA,MAAM,SAAwB,EAAC;AAG/B,EAAA,IAAI,WAAA,EAAa;AACf,IAAA,MAAA,CAAO,IAAA;AAAA,MACL;AAAA,QACE,IAAA,EAAM,MAAA;AAAA,QACN,yBACEC,cAAA,CAAC,cAAA,EAAA,EAAe,OAAA,EAAkB,IAAA,EAAK,iBAAgB,cAAA,EAAgC;AAAA,OAE3F;AAAA,MACA;AAAA,QACE,IAAA,EAAM,MAAA;AAAA,QACN,yBACEA,cAAA,CAAC,cAAA,EAAA,EAAe,OAAA,EAAkB,IAAA,EAAK,iBAAgB,cAAA,EAAgC;AAAA,OAE3F;AAAA,MACA;AAAA,QACE,IAAA,EAAM,cAAA;AAAA,QACN,OAAA,kBAASA,cAAA,CAAC,cAAA,EAAA,EAAe,OAAA,EAAkB,MAAK,uBAAA,EAAwB;AAAA;AAC1E,KACF;AAAA,EACF;AAEA,EAAA,OAAO,MAAA;AACT","file":"router.cjs","sourcesContent":["import { useEffect } from 'react';\nimport type { RouteObject } from 'react-router-dom';\n\ninterface GetInsforgeRoutesConfig {\n /**\n * Base URL of your Insforge backend\n */\n baseUrl: string;\n\n /**\n * URL to redirect to after successful sign in (when token is detected in URL)\n * @default '/'\n */\n afterSignInUrl?: string;\n\n /**\n * Whether to use built-in auth (deployed Insforge Auth)\n * When true: redirects to baseUrl/auth/* pages\n * When false: no redirect routes are added (use your own components)\n * @default true\n */\n builtInAuth?: boolean;\n\n /**\n * Custom paths for auth redirect routes\n * @default {\n * signIn: '/sign-in',\n * signUp: '/sign-up',\n * forgotPassword: '/forgot-password',\n * }\n */\n paths?: {\n signIn?: string;\n signUp?: string;\n forgotPassword?: string;\n };\n}\n\n/**\n * Helper component for redirecting to external auth\n */\nfunction RedirectToAuth({\n baseUrl,\n path,\n afterSignInUrl,\n}: {\n baseUrl: string;\n path: string;\n afterSignInUrl?: string;\n}) {\n useEffect(() => {\n // Redirect back to current URL - middleware/SDK will handle token from URL\n const currentUrl = window.location.origin + afterSignInUrl;\n const authUrl = new URL(path, baseUrl);\n authUrl.searchParams.set('redirect', currentUrl);\n window.location.replace(authUrl.toString());\n }, [baseUrl, path, afterSignInUrl]);\n\n return null;\n}\n\n/**\n * Generates Insforge authentication redirect routes for React Router.\n *\n * Returns redirect routes for sign-in, sign-up, etc. that redirect to your deployed Insforge auth pages.\n *\n * @param config - Configuration for Insforge routes\n * @returns Array of RouteObject for React Router (redirect routes only)\n *\n * @example\n * ```tsx\n * import { createBrowserRouter } from 'react-router-dom';\n * import { getInsforgeRoutes } from '@insforge/react/router';\n *\n * const router = createBrowserRouter([\n * {\n * path: '/',\n * element: <Layout />,\n * children: [\n * { index: true, element: <Home /> },\n * { path: 'dashboard', element: <Dashboard /> }\n * ]\n * },\n * // Add redirect routes (sign-in, sign-up, etc.)\n * ...getInsforgeRoutes({\n * baseUrl: 'https://your-backend.com',\n * builtInAuth: true\n * })\n * ]);\n * ```\n *\n * @example\n * ```tsx\n * // Custom paths for redirect routes\n * ...getInsforgeRoutes({\n * baseUrl: 'https://your-backend.com',\n * builtInAuth: true,\n * paths: {\n * signIn: '/login',\n * signUp: '/register'\n * }\n * })\n * ```\n */\nexport function getInsforgeRoutes(config: GetInsforgeRoutesConfig): RouteObject[] {\n const { baseUrl, builtInAuth = true, paths = {}, afterSignInUrl = '/' } = config;\n\n const { signIn = '/sign-in', signUp = '/sign-up', forgotPassword = '/forgot-password' } = paths;\n\n const routes: RouteObject[] = [];\n\n // Only add redirect routes if using built-in auth\n if (builtInAuth) {\n routes.push(\n {\n path: signIn,\n element: (\n <RedirectToAuth baseUrl={baseUrl} path=\"/auth/sign-in\" afterSignInUrl={afterSignInUrl} />\n ),\n },\n {\n path: signUp,\n element: (\n <RedirectToAuth baseUrl={baseUrl} path=\"/auth/sign-up\" afterSignInUrl={afterSignInUrl} />\n ),\n },\n {\n path: forgotPassword,\n element: <RedirectToAuth baseUrl={baseUrl} path=\"/auth/forgot-password\" />,\n }\n );\n }\n\n return routes;\n}\n"]}
package/dist/router.d.cts DELETED
@@ -1,79 +0,0 @@
1
- import { RouteObject } from 'react-router-dom';
2
-
3
- interface GetInsforgeRoutesConfig {
4
- /**
5
- * Base URL of your Insforge backend
6
- */
7
- baseUrl: string;
8
- /**
9
- * URL to redirect to after successful sign in (when token is detected in URL)
10
- * @default '/'
11
- */
12
- afterSignInUrl?: string;
13
- /**
14
- * Whether to use built-in auth (deployed Insforge Auth)
15
- * When true: redirects to baseUrl/auth/* pages
16
- * When false: no redirect routes are added (use your own components)
17
- * @default true
18
- */
19
- builtInAuth?: boolean;
20
- /**
21
- * Custom paths for auth redirect routes
22
- * @default {
23
- * signIn: '/sign-in',
24
- * signUp: '/sign-up',
25
- * forgotPassword: '/forgot-password',
26
- * }
27
- */
28
- paths?: {
29
- signIn?: string;
30
- signUp?: string;
31
- forgotPassword?: string;
32
- };
33
- }
34
- /**
35
- * Generates Insforge authentication redirect routes for React Router.
36
- *
37
- * Returns redirect routes for sign-in, sign-up, etc. that redirect to your deployed Insforge auth pages.
38
- *
39
- * @param config - Configuration for Insforge routes
40
- * @returns Array of RouteObject for React Router (redirect routes only)
41
- *
42
- * @example
43
- * ```tsx
44
- * import { createBrowserRouter } from 'react-router-dom';
45
- * import { getInsforgeRoutes } from '@insforge/react/router';
46
- *
47
- * const router = createBrowserRouter([
48
- * {
49
- * path: '/',
50
- * element: <Layout />,
51
- * children: [
52
- * { index: true, element: <Home /> },
53
- * { path: 'dashboard', element: <Dashboard /> }
54
- * ]
55
- * },
56
- * // Add redirect routes (sign-in, sign-up, etc.)
57
- * ...getInsforgeRoutes({
58
- * baseUrl: 'https://your-backend.com',
59
- * builtInAuth: true
60
- * })
61
- * ]);
62
- * ```
63
- *
64
- * @example
65
- * ```tsx
66
- * // Custom paths for redirect routes
67
- * ...getInsforgeRoutes({
68
- * baseUrl: 'https://your-backend.com',
69
- * builtInAuth: true,
70
- * paths: {
71
- * signIn: '/login',
72
- * signUp: '/register'
73
- * }
74
- * })
75
- * ```
76
- */
77
- declare function getInsforgeRoutes(config: GetInsforgeRoutesConfig): RouteObject[];
78
-
79
- export { getInsforgeRoutes };
package/dist/router.d.ts DELETED
@@ -1,79 +0,0 @@
1
- import { RouteObject } from 'react-router-dom';
2
-
3
- interface GetInsforgeRoutesConfig {
4
- /**
5
- * Base URL of your Insforge backend
6
- */
7
- baseUrl: string;
8
- /**
9
- * URL to redirect to after successful sign in (when token is detected in URL)
10
- * @default '/'
11
- */
12
- afterSignInUrl?: string;
13
- /**
14
- * Whether to use built-in auth (deployed Insforge Auth)
15
- * When true: redirects to baseUrl/auth/* pages
16
- * When false: no redirect routes are added (use your own components)
17
- * @default true
18
- */
19
- builtInAuth?: boolean;
20
- /**
21
- * Custom paths for auth redirect routes
22
- * @default {
23
- * signIn: '/sign-in',
24
- * signUp: '/sign-up',
25
- * forgotPassword: '/forgot-password',
26
- * }
27
- */
28
- paths?: {
29
- signIn?: string;
30
- signUp?: string;
31
- forgotPassword?: string;
32
- };
33
- }
34
- /**
35
- * Generates Insforge authentication redirect routes for React Router.
36
- *
37
- * Returns redirect routes for sign-in, sign-up, etc. that redirect to your deployed Insforge auth pages.
38
- *
39
- * @param config - Configuration for Insforge routes
40
- * @returns Array of RouteObject for React Router (redirect routes only)
41
- *
42
- * @example
43
- * ```tsx
44
- * import { createBrowserRouter } from 'react-router-dom';
45
- * import { getInsforgeRoutes } from '@insforge/react/router';
46
- *
47
- * const router = createBrowserRouter([
48
- * {
49
- * path: '/',
50
- * element: <Layout />,
51
- * children: [
52
- * { index: true, element: <Home /> },
53
- * { path: 'dashboard', element: <Dashboard /> }
54
- * ]
55
- * },
56
- * // Add redirect routes (sign-in, sign-up, etc.)
57
- * ...getInsforgeRoutes({
58
- * baseUrl: 'https://your-backend.com',
59
- * builtInAuth: true
60
- * })
61
- * ]);
62
- * ```
63
- *
64
- * @example
65
- * ```tsx
66
- * // Custom paths for redirect routes
67
- * ...getInsforgeRoutes({
68
- * baseUrl: 'https://your-backend.com',
69
- * builtInAuth: true,
70
- * paths: {
71
- * signIn: '/login',
72
- * signUp: '/register'
73
- * }
74
- * })
75
- * ```
76
- */
77
- declare function getInsforgeRoutes(config: GetInsforgeRoutesConfig): RouteObject[];
78
-
79
- export { getInsforgeRoutes };
package/dist/router.js DELETED
@@ -1,43 +0,0 @@
1
- import { useEffect } from 'react';
2
- import { jsx } from 'react/jsx-runtime';
3
-
4
- // src/router/getInsforgeRoutes.tsx
5
- function RedirectToAuth({
6
- baseUrl,
7
- path,
8
- afterSignInUrl
9
- }) {
10
- useEffect(() => {
11
- const currentUrl = window.location.origin + afterSignInUrl;
12
- const authUrl = new URL(path, baseUrl);
13
- authUrl.searchParams.set("redirect", currentUrl);
14
- window.location.replace(authUrl.toString());
15
- }, [baseUrl, path, afterSignInUrl]);
16
- return null;
17
- }
18
- function getInsforgeRoutes(config) {
19
- const { baseUrl, builtInAuth = true, paths = {}, afterSignInUrl = "/" } = config;
20
- const { signIn = "/sign-in", signUp = "/sign-up", forgotPassword = "/forgot-password" } = paths;
21
- const routes = [];
22
- if (builtInAuth) {
23
- routes.push(
24
- {
25
- path: signIn,
26
- element: /* @__PURE__ */ jsx(RedirectToAuth, { baseUrl, path: "/auth/sign-in", afterSignInUrl })
27
- },
28
- {
29
- path: signUp,
30
- element: /* @__PURE__ */ jsx(RedirectToAuth, { baseUrl, path: "/auth/sign-up", afterSignInUrl })
31
- },
32
- {
33
- path: forgotPassword,
34
- element: /* @__PURE__ */ jsx(RedirectToAuth, { baseUrl, path: "/auth/forgot-password" })
35
- }
36
- );
37
- }
38
- return routes;
39
- }
40
-
41
- export { getInsforgeRoutes };
42
- //# sourceMappingURL=router.js.map
43
- //# sourceMappingURL=router.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/router/getInsforgeRoutes.tsx"],"names":[],"mappings":";;;;AAyCA,SAAS,cAAA,CAAe;AAAA,EACtB,OAAA;AAAA,EACA,IAAA;AAAA,EACA;AACF,CAAA,EAIG;AACD,EAAA,SAAA,CAAU,MAAM;AAEd,IAAA,MAAM,UAAA,GAAa,MAAA,CAAO,QAAA,CAAS,MAAA,GAAS,cAAA;AAC5C,IAAA,MAAM,OAAA,GAAU,IAAI,GAAA,CAAI,IAAA,EAAM,OAAO,CAAA;AACrC,IAAA,OAAA,CAAQ,YAAA,CAAa,GAAA,CAAI,UAAA,EAAY,UAAU,CAAA;AAC/C,IAAA,MAAA,CAAO,QAAA,CAAS,OAAA,CAAQ,OAAA,CAAQ,QAAA,EAAU,CAAA;AAAA,EAC5C,CAAA,EAAG,CAAC,OAAA,EAAS,IAAA,EAAM,cAAc,CAAC,CAAA;AAElC,EAAA,OAAO,IAAA;AACT;AA6CO,SAAS,kBAAkB,MAAA,EAAgD;AAChF,EAAA,MAAM,EAAE,SAAS,WAAA,GAAc,IAAA,EAAM,QAAQ,EAAC,EAAG,cAAA,GAAiB,GAAA,EAAI,GAAI,MAAA;AAE1E,EAAA,MAAM,EAAE,MAAA,GAAS,UAAA,EAAY,SAAS,UAAA,EAAY,cAAA,GAAiB,oBAAmB,GAAI,KAAA;AAE1F,EAAA,MAAM,SAAwB,EAAC;AAG/B,EAAA,IAAI,WAAA,EAAa;AACf,IAAA,MAAA,CAAO,IAAA;AAAA,MACL;AAAA,QACE,IAAA,EAAM,MAAA;AAAA,QACN,yBACE,GAAA,CAAC,cAAA,EAAA,EAAe,OAAA,EAAkB,IAAA,EAAK,iBAAgB,cAAA,EAAgC;AAAA,OAE3F;AAAA,MACA;AAAA,QACE,IAAA,EAAM,MAAA;AAAA,QACN,yBACE,GAAA,CAAC,cAAA,EAAA,EAAe,OAAA,EAAkB,IAAA,EAAK,iBAAgB,cAAA,EAAgC;AAAA,OAE3F;AAAA,MACA;AAAA,QACE,IAAA,EAAM,cAAA;AAAA,QACN,OAAA,kBAAS,GAAA,CAAC,cAAA,EAAA,EAAe,OAAA,EAAkB,MAAK,uBAAA,EAAwB;AAAA;AAC1E,KACF;AAAA,EACF;AAEA,EAAA,OAAO,MAAA;AACT","file":"router.js","sourcesContent":["import { useEffect } from 'react';\nimport type { RouteObject } from 'react-router-dom';\n\ninterface GetInsforgeRoutesConfig {\n /**\n * Base URL of your Insforge backend\n */\n baseUrl: string;\n\n /**\n * URL to redirect to after successful sign in (when token is detected in URL)\n * @default '/'\n */\n afterSignInUrl?: string;\n\n /**\n * Whether to use built-in auth (deployed Insforge Auth)\n * When true: redirects to baseUrl/auth/* pages\n * When false: no redirect routes are added (use your own components)\n * @default true\n */\n builtInAuth?: boolean;\n\n /**\n * Custom paths for auth redirect routes\n * @default {\n * signIn: '/sign-in',\n * signUp: '/sign-up',\n * forgotPassword: '/forgot-password',\n * }\n */\n paths?: {\n signIn?: string;\n signUp?: string;\n forgotPassword?: string;\n };\n}\n\n/**\n * Helper component for redirecting to external auth\n */\nfunction RedirectToAuth({\n baseUrl,\n path,\n afterSignInUrl,\n}: {\n baseUrl: string;\n path: string;\n afterSignInUrl?: string;\n}) {\n useEffect(() => {\n // Redirect back to current URL - middleware/SDK will handle token from URL\n const currentUrl = window.location.origin + afterSignInUrl;\n const authUrl = new URL(path, baseUrl);\n authUrl.searchParams.set('redirect', currentUrl);\n window.location.replace(authUrl.toString());\n }, [baseUrl, path, afterSignInUrl]);\n\n return null;\n}\n\n/**\n * Generates Insforge authentication redirect routes for React Router.\n *\n * Returns redirect routes for sign-in, sign-up, etc. that redirect to your deployed Insforge auth pages.\n *\n * @param config - Configuration for Insforge routes\n * @returns Array of RouteObject for React Router (redirect routes only)\n *\n * @example\n * ```tsx\n * import { createBrowserRouter } from 'react-router-dom';\n * import { getInsforgeRoutes } from '@insforge/react/router';\n *\n * const router = createBrowserRouter([\n * {\n * path: '/',\n * element: <Layout />,\n * children: [\n * { index: true, element: <Home /> },\n * { path: 'dashboard', element: <Dashboard /> }\n * ]\n * },\n * // Add redirect routes (sign-in, sign-up, etc.)\n * ...getInsforgeRoutes({\n * baseUrl: 'https://your-backend.com',\n * builtInAuth: true\n * })\n * ]);\n * ```\n *\n * @example\n * ```tsx\n * // Custom paths for redirect routes\n * ...getInsforgeRoutes({\n * baseUrl: 'https://your-backend.com',\n * builtInAuth: true,\n * paths: {\n * signIn: '/login',\n * signUp: '/register'\n * }\n * })\n * ```\n */\nexport function getInsforgeRoutes(config: GetInsforgeRoutesConfig): RouteObject[] {\n const { baseUrl, builtInAuth = true, paths = {}, afterSignInUrl = '/' } = config;\n\n const { signIn = '/sign-in', signUp = '/sign-up', forgotPassword = '/forgot-password' } = paths;\n\n const routes: RouteObject[] = [];\n\n // Only add redirect routes if using built-in auth\n if (builtInAuth) {\n routes.push(\n {\n path: signIn,\n element: (\n <RedirectToAuth baseUrl={baseUrl} path=\"/auth/sign-in\" afterSignInUrl={afterSignInUrl} />\n ),\n },\n {\n path: signUp,\n element: (\n <RedirectToAuth baseUrl={baseUrl} path=\"/auth/sign-up\" afterSignInUrl={afterSignInUrl} />\n ),\n },\n {\n path: forgotPassword,\n element: <RedirectToAuth baseUrl={baseUrl} path=\"/auth/forgot-password\" />,\n }\n );\n }\n\n return routes;\n}\n"]}