@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.
- package/README.md +426 -439
- package/dist/atoms.cjs +46 -6
- package/dist/atoms.cjs.map +1 -1
- package/dist/atoms.js +46 -6
- package/dist/atoms.js.map +1 -1
- package/dist/components.cjs +51 -11
- package/dist/components.cjs.map +1 -1
- package/dist/components.js +51 -11
- package/dist/components.js.map +1 -1
- package/dist/forms.cjs +46 -6
- package/dist/forms.cjs.map +1 -1
- package/dist/forms.js +46 -6
- package/dist/forms.js.map +1 -1
- package/dist/hooks.cjs +27 -1
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.js +27 -1
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +83 -49
- 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 +81 -50
- 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,12 +410,37 @@ function InsforgeProvider({
|
|
|
371
410
|
},
|
|
372
411
|
children
|
|
373
412
|
}
|
|
374
|
-
);
|
|
413
|
+
) });
|
|
375
414
|
}
|
|
376
415
|
function useInsforge() {
|
|
377
416
|
const context = useContext(InsforgeContext);
|
|
378
417
|
if (!context) {
|
|
379
|
-
|
|
418
|
+
if (typeof window !== "undefined") {
|
|
419
|
+
throw new Error("useInsforge must be used within InsforgeProvider");
|
|
420
|
+
}
|
|
421
|
+
return {
|
|
422
|
+
user: null,
|
|
423
|
+
isLoaded: false,
|
|
424
|
+
isSignedIn: false,
|
|
425
|
+
setUser: () => {
|
|
426
|
+
},
|
|
427
|
+
signIn: async () => ({ error: "SSR mode" }),
|
|
428
|
+
signUp: async () => ({ error: "SSR mode" }),
|
|
429
|
+
signOut: async () => {
|
|
430
|
+
},
|
|
431
|
+
updateUser: async () => {
|
|
432
|
+
},
|
|
433
|
+
reloadAuth: async () => ({ success: false, error: "SSR mode" }),
|
|
434
|
+
sendVerificationEmail: async () => null,
|
|
435
|
+
sendResetPasswordEmail: async () => null,
|
|
436
|
+
resetPassword: async () => null,
|
|
437
|
+
verifyEmail: async () => null,
|
|
438
|
+
exchangeResetPasswordToken: async () => ({ error: { message: "SSR mode" } }),
|
|
439
|
+
loginWithOAuth: async () => {
|
|
440
|
+
},
|
|
441
|
+
getPublicAuthConfig: async () => null,
|
|
442
|
+
baseUrl: ""
|
|
443
|
+
};
|
|
380
444
|
}
|
|
381
445
|
return context;
|
|
382
446
|
}
|
|
@@ -589,7 +653,8 @@ function AuthPasswordField({
|
|
|
589
653
|
onFocus,
|
|
590
654
|
...props
|
|
591
655
|
}) {
|
|
592
|
-
const
|
|
656
|
+
const searchParams = useSearchParams();
|
|
657
|
+
const { Link } = useNavigationAdapter();
|
|
593
658
|
const [showPassword, setShowPassword] = useState(false);
|
|
594
659
|
const [showStrength, setShowStrength] = useState(false);
|
|
595
660
|
const resolvedForgotPasswordHref = useMemo(
|
|
@@ -605,7 +670,7 @@ function AuthPasswordField({
|
|
|
605
670
|
return /* @__PURE__ */ jsxs("div", { className: "if-passwordField if-internal-p5w9m7", children: [
|
|
606
671
|
(label || forgotPasswordLink) && /* @__PURE__ */ jsxs("div", { className: "if-passwordField-labelRow", children: [
|
|
607
672
|
/* @__PURE__ */ jsx("label", { htmlFor: id, className: "if-passwordField-label", children: label }),
|
|
608
|
-
forgotPasswordLink && resolvedForgotPasswordHref && /* @__PURE__ */ jsx(
|
|
673
|
+
forgotPasswordLink && resolvedForgotPasswordHref && /* @__PURE__ */ jsx(Link, { href: resolvedForgotPasswordHref, className: "if-passwordField-forgotLink", children: forgotPasswordLink.text || "Forget Password?" })
|
|
609
674
|
] }),
|
|
610
675
|
/* @__PURE__ */ jsxs("div", { className: "if-passwordField-inputWrapper", children: [
|
|
611
676
|
/* @__PURE__ */ jsx(
|
|
@@ -657,12 +722,13 @@ function AuthSubmitButton({
|
|
|
657
722
|
);
|
|
658
723
|
}
|
|
659
724
|
function AuthLink({ text, linkText, href }) {
|
|
660
|
-
const
|
|
725
|
+
const searchParams = useSearchParams();
|
|
726
|
+
const { Link } = useNavigationAdapter();
|
|
661
727
|
const finalHref = resolveAuthUrl(href, searchParams);
|
|
662
728
|
return /* @__PURE__ */ jsxs("p", { className: "if-authLink if-internal-al5w9p", children: [
|
|
663
729
|
text && /* @__PURE__ */ jsx("span", { className: "if-authLink-text", children: text }),
|
|
664
730
|
text && " ",
|
|
665
|
-
/* @__PURE__ */ jsx(
|
|
731
|
+
/* @__PURE__ */ jsx(Link, { href: finalHref, className: "if-authLink-link", children: linkText })
|
|
666
732
|
] });
|
|
667
733
|
}
|
|
668
734
|
function AuthDivider({ text = "or" }) {
|
|
@@ -1305,7 +1371,7 @@ function SignIn({ onError, ...uiProps }) {
|
|
|
1305
1371
|
const [loading, setLoading] = useState(false);
|
|
1306
1372
|
const [step, setStep] = useState("form");
|
|
1307
1373
|
const [oauthLoading] = useState(null);
|
|
1308
|
-
const
|
|
1374
|
+
const searchParams = useSearchParams();
|
|
1309
1375
|
const redirectUrl = searchParams.get("redirect");
|
|
1310
1376
|
async function handleSubmit(e) {
|
|
1311
1377
|
e.preventDefault();
|
|
@@ -1557,7 +1623,7 @@ function SignUp({ onError, ...uiProps }) {
|
|
|
1557
1623
|
const [loading, setLoading] = useState(false);
|
|
1558
1624
|
const [step, setStep] = useState("form");
|
|
1559
1625
|
const [oauthLoading] = useState(null);
|
|
1560
|
-
const
|
|
1626
|
+
const searchParams = useSearchParams();
|
|
1561
1627
|
const redirectUrl = searchParams.get("redirect");
|
|
1562
1628
|
async function handleSubmit(e) {
|
|
1563
1629
|
e.preventDefault();
|
|
@@ -1822,7 +1888,7 @@ function ResetPasswordForm({
|
|
|
1822
1888
|
function ForgotPassword({ onError, ...uiProps }) {
|
|
1823
1889
|
const { sendResetPasswordEmail, exchangeResetPasswordToken, resetPassword } = useInsforge();
|
|
1824
1890
|
const { authConfig } = usePublicAuthConfig();
|
|
1825
|
-
const
|
|
1891
|
+
const searchParams = useSearchParams();
|
|
1826
1892
|
const [step, setStep] = useState("email");
|
|
1827
1893
|
const [email, setEmail] = useState("");
|
|
1828
1894
|
const [resetToken, setResetToken] = useState("");
|
|
@@ -1978,7 +2044,7 @@ function ForgotPassword({ onError, ...uiProps }) {
|
|
|
1978
2044
|
);
|
|
1979
2045
|
}
|
|
1980
2046
|
function ResetPassword({ onError, ...uiProps }) {
|
|
1981
|
-
const
|
|
2047
|
+
const searchParams = useSearchParams();
|
|
1982
2048
|
const token = searchParams.get("token");
|
|
1983
2049
|
const { resetPassword } = useInsforge();
|
|
1984
2050
|
const { authConfig } = usePublicAuthConfig();
|
|
@@ -2399,42 +2465,7 @@ function useUser() {
|
|
|
2399
2465
|
const { user, isLoaded, updateUser, setUser } = useInsforge();
|
|
2400
2466
|
return { user, isLoaded, updateUser, setUser };
|
|
2401
2467
|
}
|
|
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
2468
|
|
|
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,
|
|
2469
|
+
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
2470
|
//# sourceMappingURL=index.js.map
|
|
2440
2471
|
//# sourceMappingURL=index.js.map
|