@insforge/react 0.4.11 → 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,13 +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
 
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
+ }
22
62
  var InsforgeContext = createContext(void 0);
23
63
  function InsforgeProvider({
24
64
  children,
@@ -346,7 +386,7 @@ function InsforgeProvider({
346
386
  },
347
387
  [insforge, afterSignInUrl]
348
388
  );
349
- return /* @__PURE__ */ jsx(
389
+ return /* @__PURE__ */ jsx(NavigationProvider, { adapter: BrowserNavigationAdapter, children: /* @__PURE__ */ jsx(
350
390
  InsforgeContext.Provider,
351
391
  {
352
392
  value: {
@@ -370,7 +410,7 @@ function InsforgeProvider({
370
410
  },
371
411
  children
372
412
  }
373
- );
413
+ ) });
374
414
  }
375
415
  function useInsforge() {
376
416
  const context = useContext(InsforgeContext);
@@ -588,7 +628,8 @@ function AuthPasswordField({
588
628
  onFocus,
589
629
  ...props
590
630
  }) {
591
- const [searchParams] = useSearchParams();
631
+ const searchParams = useSearchParams();
632
+ const { Link } = useNavigationAdapter();
592
633
  const [showPassword, setShowPassword] = useState(false);
593
634
  const [showStrength, setShowStrength] = useState(false);
594
635
  const resolvedForgotPasswordHref = useMemo(
@@ -604,7 +645,7 @@ function AuthPasswordField({
604
645
  return /* @__PURE__ */ jsxs("div", { className: "if-passwordField if-internal-p5w9m7", children: [
605
646
  (label || forgotPasswordLink) && /* @__PURE__ */ jsxs("div", { className: "if-passwordField-labelRow", children: [
606
647
  /* @__PURE__ */ jsx("label", { htmlFor: id, className: "if-passwordField-label", children: label }),
607
- 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?" })
608
649
  ] }),
609
650
  /* @__PURE__ */ jsxs("div", { className: "if-passwordField-inputWrapper", children: [
610
651
  /* @__PURE__ */ jsx(
@@ -656,12 +697,13 @@ function AuthSubmitButton({
656
697
  );
657
698
  }
658
699
  function AuthLink({ text, linkText, href }) {
659
- const [searchParams] = useSearchParams();
700
+ const searchParams = useSearchParams();
701
+ const { Link } = useNavigationAdapter();
660
702
  const finalHref = resolveAuthUrl(href, searchParams);
661
703
  return /* @__PURE__ */ jsxs("p", { className: "if-authLink if-internal-al5w9p", children: [
662
704
  text && /* @__PURE__ */ jsx("span", { className: "if-authLink-text", children: text }),
663
705
  text && " ",
664
- /* @__PURE__ */ jsx("a", { href: finalHref, className: "if-authLink-link", children: linkText })
706
+ /* @__PURE__ */ jsx(Link, { href: finalHref, className: "if-authLink-link", children: linkText })
665
707
  ] });
666
708
  }
667
709
  function AuthDivider({ text = "or" }) {
@@ -1304,7 +1346,7 @@ function SignIn({ onError, ...uiProps }) {
1304
1346
  const [loading, setLoading] = useState(false);
1305
1347
  const [step, setStep] = useState("form");
1306
1348
  const [oauthLoading] = useState(null);
1307
- const [searchParams] = useSearchParams();
1349
+ const searchParams = useSearchParams();
1308
1350
  const redirectUrl = searchParams.get("redirect");
1309
1351
  async function handleSubmit(e) {
1310
1352
  e.preventDefault();
@@ -1556,7 +1598,7 @@ function SignUp({ onError, ...uiProps }) {
1556
1598
  const [loading, setLoading] = useState(false);
1557
1599
  const [step, setStep] = useState("form");
1558
1600
  const [oauthLoading] = useState(null);
1559
- const [searchParams] = useSearchParams();
1601
+ const searchParams = useSearchParams();
1560
1602
  const redirectUrl = searchParams.get("redirect");
1561
1603
  async function handleSubmit(e) {
1562
1604
  e.preventDefault();
@@ -1821,7 +1863,7 @@ function ResetPasswordForm({
1821
1863
  function ForgotPassword({ onError, ...uiProps }) {
1822
1864
  const { sendResetPasswordEmail, exchangeResetPasswordToken, resetPassword } = useInsforge();
1823
1865
  const { authConfig } = usePublicAuthConfig();
1824
- const [searchParams] = useSearchParams();
1866
+ const searchParams = useSearchParams();
1825
1867
  const [step, setStep] = useState("email");
1826
1868
  const [email, setEmail] = useState("");
1827
1869
  const [resetToken, setResetToken] = useState("");
@@ -1977,7 +2019,7 @@ function ForgotPassword({ onError, ...uiProps }) {
1977
2019
  );
1978
2020
  }
1979
2021
  function ResetPassword({ onError, ...uiProps }) {
1980
- const [searchParams] = useSearchParams();
2022
+ const searchParams = useSearchParams();
1981
2023
  const token = searchParams.get("token");
1982
2024
  const { resetPassword } = useInsforge();
1983
2025
  const { authConfig } = usePublicAuthConfig();
@@ -2398,42 +2440,7 @@ function useUser() {
2398
2440
  const { user, isLoaded, updateUser, setUser } = useInsforge();
2399
2441
  return { user, isLoaded, updateUser, setUser };
2400
2442
  }
2401
- function RedirectToAuth({
2402
- baseUrl,
2403
- path,
2404
- afterSignInUrl
2405
- }) {
2406
- useEffect(() => {
2407
- const currentUrl = window.location.origin + afterSignInUrl;
2408
- const authUrl = new URL(path, baseUrl);
2409
- authUrl.searchParams.set("redirect", currentUrl);
2410
- window.location.replace(authUrl.toString());
2411
- }, [baseUrl, path, afterSignInUrl]);
2412
- return null;
2413
- }
2414
- function getInsforgeRoutes(config) {
2415
- const { baseUrl, builtInAuth = true, paths = {}, afterSignInUrl = "/" } = config;
2416
- const { signIn = "/sign-in", signUp = "/sign-up", forgotPassword = "/forgot-password" } = paths;
2417
- const routes = [];
2418
- if (builtInAuth) {
2419
- routes.push(
2420
- {
2421
- path: signIn,
2422
- element: /* @__PURE__ */ jsx(RedirectToAuth, { baseUrl, path: "/auth/sign-in", afterSignInUrl })
2423
- },
2424
- {
2425
- path: signUp,
2426
- element: /* @__PURE__ */ jsx(RedirectToAuth, { baseUrl, path: "/auth/sign-up", afterSignInUrl })
2427
- },
2428
- {
2429
- path: forgotPassword,
2430
- element: /* @__PURE__ */ jsx(RedirectToAuth, { baseUrl, path: "/auth/forgot-password" })
2431
- }
2432
- );
2433
- }
2434
- return routes;
2435
- }
2436
2443
 
2437
- 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 };
2438
2445
  //# sourceMappingURL=index.js.map
2439
2446
  //# sourceMappingURL=index.js.map