@insforge/react 0.4.12 → 0.5.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.
package/dist/index.d.cts CHANGED
@@ -9,9 +9,8 @@ export { AuthConfig, EmailVerificationMethod } from './types.cjs';
9
9
  import { CreateSessionResponse, CreateUserResponse, ResetPasswordResponse, GetPublicAuthConfigResponse } from '@insforge/shared-schemas';
10
10
  export { useAuth, usePublicAuthConfig, useUser } from './hooks.cjs';
11
11
  export { checkPasswordStrength, createPasswordSchema, emailSchema, passwordSchema, resolveAuthPath, resolveAuthUrl, validateEmail, validatePassword } from './lib.cjs';
12
- export { getInsforgeRoutes } from './router.cjs';
12
+ export { BrowserNavigationAdapter, NavigationAdapter, NavigationProvider, NavigationProviderProps, useNavigationAdapter, useSearchParams } from './navigation.cjs';
13
13
  import 'zod';
14
- import 'react-router-dom';
15
14
 
16
15
  interface InsforgeContextValue {
17
16
  user: InsforgeUser | null;
package/dist/index.d.ts CHANGED
@@ -9,9 +9,8 @@ export { AuthConfig, EmailVerificationMethod } from './types.js';
9
9
  import { CreateSessionResponse, CreateUserResponse, ResetPasswordResponse, GetPublicAuthConfigResponse } from '@insforge/shared-schemas';
10
10
  export { useAuth, usePublicAuthConfig, useUser } from './hooks.js';
11
11
  export { checkPasswordStrength, createPasswordSchema, emailSchema, passwordSchema, resolveAuthPath, resolveAuthUrl, validateEmail, validatePassword } from './lib.js';
12
- export { getInsforgeRoutes } from './router.js';
12
+ export { BrowserNavigationAdapter, NavigationAdapter, NavigationProvider, NavigationProviderProps, useNavigationAdapter, useSearchParams } from './navigation.js';
13
13
  import 'zod';
14
- import 'react-router-dom';
15
14
 
16
15
  interface InsforgeContextValue {
17
16
  user: InsforgeUser | null;
package/dist/index.js CHANGED
@@ -12,14 +12,53 @@ if (typeof document !== 'undefined' && typeof window !== 'undefined') {
12
12
  }
13
13
  }
14
14
 
15
- import { createContext, useState, useRef, useCallback, useEffect, useContext, useMemo } from 'react';
16
- import { useSearchParams } from 'react-router-dom';
17
- import { createClient } from '@insforge/sdk';
15
+ import { createContext, useContext, useState, useRef, useCallback, useEffect, useMemo } from 'react';
18
16
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
17
+ import { createClient } from '@insforge/sdk';
19
18
  import { AlertTriangle, Check, EyeOff, Eye, Loader2, CircleCheck, LogOut } from 'lucide-react';
20
19
  import { z } from 'zod';
21
20
 
22
21
  // src/components/SignIn.tsx
22
+ var NavigationContext = createContext(null);
23
+ function NavigationProvider({ adapter, children }) {
24
+ return /* @__PURE__ */ jsx(NavigationContext.Provider, { value: adapter, children });
25
+ }
26
+ function useNavigationAdapter() {
27
+ const adapter = useContext(NavigationContext);
28
+ if (!adapter) {
29
+ throw new Error("useNavigationAdapter must be used within NavigationProvider");
30
+ }
31
+ return adapter;
32
+ }
33
+ var BrowserNavigationAdapter = {
34
+ /**
35
+ * Returns URLSearchParams from current window.location.search
36
+ * Note: Not reactive - reads once on component mount
37
+ * This is sufficient for auth flows where we read initial URL params
38
+ */
39
+ useSearchParams() {
40
+ const [searchParams] = useState(() => {
41
+ if (typeof window === "undefined") {
42
+ return new URLSearchParams();
43
+ }
44
+ return new URLSearchParams(window.location.search);
45
+ });
46
+ return searchParams;
47
+ },
48
+ /**
49
+ * Native <a> tag for navigation
50
+ * Uses full page reload
51
+ */
52
+ Link({ href, className, children }) {
53
+ return /* @__PURE__ */ jsx("a", { href, className, children });
54
+ }
55
+ };
56
+
57
+ // src/navigation/useSearchParams.ts
58
+ function useSearchParams() {
59
+ const adapter = useNavigationAdapter();
60
+ return adapter.useSearchParams();
61
+ }
23
62
  var InsforgeContext = createContext(void 0);
24
63
  function InsforgeProvider({
25
64
  children,
@@ -347,7 +386,7 @@ function InsforgeProvider({
347
386
  },
348
387
  [insforge, afterSignInUrl]
349
388
  );
350
- return /* @__PURE__ */ jsx(
389
+ return /* @__PURE__ */ jsx(NavigationProvider, { adapter: BrowserNavigationAdapter, children: /* @__PURE__ */ jsx(
351
390
  InsforgeContext.Provider,
352
391
  {
353
392
  value: {
@@ -371,7 +410,7 @@ function InsforgeProvider({
371
410
  },
372
411
  children
373
412
  }
374
- );
413
+ ) });
375
414
  }
376
415
  function useInsforge() {
377
416
  const context = useContext(InsforgeContext);
@@ -589,7 +628,8 @@ function AuthPasswordField({
589
628
  onFocus,
590
629
  ...props
591
630
  }) {
592
- const [searchParams] = useSearchParams();
631
+ const searchParams = useSearchParams();
632
+ const { Link } = useNavigationAdapter();
593
633
  const [showPassword, setShowPassword] = useState(false);
594
634
  const [showStrength, setShowStrength] = useState(false);
595
635
  const resolvedForgotPasswordHref = useMemo(
@@ -605,7 +645,7 @@ function AuthPasswordField({
605
645
  return /* @__PURE__ */ jsxs("div", { className: "if-passwordField if-internal-p5w9m7", children: [
606
646
  (label || forgotPasswordLink) && /* @__PURE__ */ jsxs("div", { className: "if-passwordField-labelRow", children: [
607
647
  /* @__PURE__ */ jsx("label", { htmlFor: id, className: "if-passwordField-label", children: label }),
608
- forgotPasswordLink && resolvedForgotPasswordHref && /* @__PURE__ */ jsx("a", { href: resolvedForgotPasswordHref, className: "if-passwordField-forgotLink", children: forgotPasswordLink.text || "Forget Password?" })
648
+ forgotPasswordLink && resolvedForgotPasswordHref && /* @__PURE__ */ jsx(Link, { href: resolvedForgotPasswordHref, className: "if-passwordField-forgotLink", children: forgotPasswordLink.text || "Forget Password?" })
609
649
  ] }),
610
650
  /* @__PURE__ */ jsxs("div", { className: "if-passwordField-inputWrapper", children: [
611
651
  /* @__PURE__ */ jsx(
@@ -657,12 +697,13 @@ function AuthSubmitButton({
657
697
  );
658
698
  }
659
699
  function AuthLink({ text, linkText, href }) {
660
- const [searchParams] = useSearchParams();
700
+ const searchParams = useSearchParams();
701
+ const { Link } = useNavigationAdapter();
661
702
  const finalHref = resolveAuthUrl(href, searchParams);
662
703
  return /* @__PURE__ */ jsxs("p", { className: "if-authLink if-internal-al5w9p", children: [
663
704
  text && /* @__PURE__ */ jsx("span", { className: "if-authLink-text", children: text }),
664
705
  text && " ",
665
- /* @__PURE__ */ jsx("a", { href: finalHref, className: "if-authLink-link", children: linkText })
706
+ /* @__PURE__ */ jsx(Link, { href: finalHref, className: "if-authLink-link", children: linkText })
666
707
  ] });
667
708
  }
668
709
  function AuthDivider({ text = "or" }) {
@@ -1305,7 +1346,7 @@ function SignIn({ onError, ...uiProps }) {
1305
1346
  const [loading, setLoading] = useState(false);
1306
1347
  const [step, setStep] = useState("form");
1307
1348
  const [oauthLoading] = useState(null);
1308
- const [searchParams] = useSearchParams();
1349
+ const searchParams = useSearchParams();
1309
1350
  const redirectUrl = searchParams.get("redirect");
1310
1351
  async function handleSubmit(e) {
1311
1352
  e.preventDefault();
@@ -1557,7 +1598,7 @@ function SignUp({ onError, ...uiProps }) {
1557
1598
  const [loading, setLoading] = useState(false);
1558
1599
  const [step, setStep] = useState("form");
1559
1600
  const [oauthLoading] = useState(null);
1560
- const [searchParams] = useSearchParams();
1601
+ const searchParams = useSearchParams();
1561
1602
  const redirectUrl = searchParams.get("redirect");
1562
1603
  async function handleSubmit(e) {
1563
1604
  e.preventDefault();
@@ -1822,7 +1863,7 @@ function ResetPasswordForm({
1822
1863
  function ForgotPassword({ onError, ...uiProps }) {
1823
1864
  const { sendResetPasswordEmail, exchangeResetPasswordToken, resetPassword } = useInsforge();
1824
1865
  const { authConfig } = usePublicAuthConfig();
1825
- const [searchParams] = useSearchParams();
1866
+ const searchParams = useSearchParams();
1826
1867
  const [step, setStep] = useState("email");
1827
1868
  const [email, setEmail] = useState("");
1828
1869
  const [resetToken, setResetToken] = useState("");
@@ -1978,7 +2019,7 @@ function ForgotPassword({ onError, ...uiProps }) {
1978
2019
  );
1979
2020
  }
1980
2021
  function ResetPassword({ onError, ...uiProps }) {
1981
- const [searchParams] = useSearchParams();
2022
+ const searchParams = useSearchParams();
1982
2023
  const token = searchParams.get("token");
1983
2024
  const { resetPassword } = useInsforge();
1984
2025
  const { authConfig } = usePublicAuthConfig();
@@ -2399,42 +2440,7 @@ function useUser() {
2399
2440
  const { user, isLoaded, updateUser, setUser } = useInsforge();
2400
2441
  return { user, isLoaded, updateUser, setUser };
2401
2442
  }
2402
- function RedirectToAuth({
2403
- baseUrl,
2404
- path,
2405
- afterSignInUrl
2406
- }) {
2407
- useEffect(() => {
2408
- const currentUrl = window.location.origin + afterSignInUrl;
2409
- const authUrl = new URL(path, baseUrl);
2410
- authUrl.searchParams.set("redirect", currentUrl);
2411
- window.location.replace(authUrl.toString());
2412
- }, [baseUrl, path, afterSignInUrl]);
2413
- return null;
2414
- }
2415
- function getInsforgeRoutes(config) {
2416
- const { baseUrl, builtInAuth = true, paths = {}, afterSignInUrl = "/" } = config;
2417
- const { signIn = "/sign-in", signUp = "/sign-up", forgotPassword = "/forgot-password" } = paths;
2418
- const routes = [];
2419
- if (builtInAuth) {
2420
- routes.push(
2421
- {
2422
- path: signIn,
2423
- element: /* @__PURE__ */ jsx(RedirectToAuth, { baseUrl, path: "/auth/sign-in", afterSignInUrl })
2424
- },
2425
- {
2426
- path: signUp,
2427
- element: /* @__PURE__ */ jsx(RedirectToAuth, { baseUrl, path: "/auth/sign-up", afterSignInUrl })
2428
- },
2429
- {
2430
- path: forgotPassword,
2431
- element: /* @__PURE__ */ jsx(RedirectToAuth, { baseUrl, path: "/auth/forgot-password" })
2432
- }
2433
- );
2434
- }
2435
- return routes;
2436
- }
2437
2443
 
2438
- export { AuthBranding, AuthContainer, AuthDivider, AuthEmailVerificationStep, AuthErrorBanner, AuthFormField, AuthHeader, AuthLink, AuthOAuthButton, AuthOAuthProviders, AuthPasswordField, AuthPasswordStrengthIndicator, AuthResetPasswordVerificationStep, AuthSubmitButton, AuthVerificationCodeInput, ForgotPassword, ForgotPasswordForm, InsforgeProvider, OAUTH_PROVIDER_CONFIG, Protect, ResetPassword, ResetPasswordForm, SignIn, SignInForm, SignUp, SignUpForm, SignedIn, SignedOut, UserButton, VerifyEmail, VerifyEmailStatus, checkPasswordStrength, createPasswordSchema, emailSchema, getAllProviderConfigs, getInsforgeRoutes, getProviderConfig, passwordSchema, resolveAuthPath, resolveAuthUrl, useAuth, useInsforge, usePublicAuthConfig, useUser, validateEmail, validatePassword };
2444
+ export { AuthBranding, AuthContainer, AuthDivider, AuthEmailVerificationStep, AuthErrorBanner, AuthFormField, AuthHeader, AuthLink, AuthOAuthButton, AuthOAuthProviders, AuthPasswordField, AuthPasswordStrengthIndicator, AuthResetPasswordVerificationStep, AuthSubmitButton, AuthVerificationCodeInput, BrowserNavigationAdapter, ForgotPassword, ForgotPasswordForm, InsforgeProvider, NavigationProvider, OAUTH_PROVIDER_CONFIG, Protect, ResetPassword, ResetPasswordForm, SignIn, SignInForm, SignUp, SignUpForm, SignedIn, SignedOut, UserButton, VerifyEmail, VerifyEmailStatus, checkPasswordStrength, createPasswordSchema, emailSchema, getAllProviderConfigs, getProviderConfig, passwordSchema, resolveAuthPath, resolveAuthUrl, useAuth, useInsforge, useNavigationAdapter, usePublicAuthConfig, useSearchParams, useUser, validateEmail, validatePassword };
2439
2445
  //# sourceMappingURL=index.js.map
2440
2446
  //# sourceMappingURL=index.js.map