@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/atoms.cjs +20 -5
- package/dist/atoms.cjs.map +1 -1
- package/dist/atoms.js +20 -5
- package/dist/atoms.js.map +1 -1
- package/dist/components.cjs +25 -10
- package/dist/components.cjs.map +1 -1
- package/dist/components.js +25 -10
- package/dist/components.js.map +1 -1
- package/dist/forms.cjs +20 -5
- package/dist/forms.cjs.map +1 -1
- package/dist/forms.js +20 -5
- package/dist/forms.js.map +1 -1
- package/dist/hooks.cjs +1 -0
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.js +1 -0
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +57 -48
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +55 -49
- package/dist/index.js.map +1 -1
- package/dist/navigation.cjs +53 -0
- package/dist/navigation.cjs.map +1 -0
- package/dist/navigation.d.cts +64 -0
- package/dist/navigation.d.ts +64 -0
- package/dist/navigation.js +48 -0
- package/dist/navigation.js.map +1 -0
- package/package.json +6 -7
- package/dist/router.cjs +0 -45
- package/dist/router.cjs.map +0 -1
- package/dist/router.d.cts +0 -79
- package/dist/router.d.ts +0 -79
- package/dist/router.js +0 -43
- package/dist/router.js.map +0 -1
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 {
|
|
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 {
|
|
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,
|
|
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
|
|
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(
|
|
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
|
|
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(
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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,
|
|
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
|