@insforge/react 0.6.4 → 0.6.6
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 +3 -2
- package/dist/atoms.cjs.map +1 -1
- package/dist/atoms.js +3 -2
- package/dist/atoms.js.map +1 -1
- package/dist/components.cjs +17 -22
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +16 -0
- package/dist/components.d.ts +16 -0
- package/dist/components.js +17 -22
- package/dist/components.js.map +1 -1
- package/dist/forms.cjs +3 -2
- package/dist/forms.cjs.map +1 -1
- package/dist/forms.js +3 -2
- package/dist/forms.js.map +1 -1
- package/dist/hooks.cjs +3 -2
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.cts +2 -2
- package/dist/hooks.d.ts +2 -2
- package/dist/hooks.js +3 -2
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +63 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -2
- package/dist/index.d.ts +11 -2
- package/dist/index.js +63 -34
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/components.d.cts
CHANGED
|
@@ -223,6 +223,14 @@ interface ConditionalProps$1 {
|
|
|
223
223
|
/**
|
|
224
224
|
* Conditional component that renders children only when user is signed in.
|
|
225
225
|
*
|
|
226
|
+
* Uses userId to determine rendering:
|
|
227
|
+
* - undefined = not loaded yet (SSR or before hydration) -> render null
|
|
228
|
+
* - null = loaded, user signed out -> render null
|
|
229
|
+
* - string = loaded, user signed in -> render children
|
|
230
|
+
*
|
|
231
|
+
* This prevents hydration mismatches in Next.js SSR by ensuring
|
|
232
|
+
* consistent rendering between server and client initial render.
|
|
233
|
+
*
|
|
226
234
|
* @component
|
|
227
235
|
* @example
|
|
228
236
|
* ```tsx
|
|
@@ -242,6 +250,14 @@ interface ConditionalProps {
|
|
|
242
250
|
/**
|
|
243
251
|
* Conditional component that renders children only when user is signed out.
|
|
244
252
|
*
|
|
253
|
+
* Uses userId to determine rendering:
|
|
254
|
+
* - undefined = not loaded yet (SSR or before hydration) -> render null
|
|
255
|
+
* - null = loaded, user signed out -> render children
|
|
256
|
+
* - string = loaded, user signed in -> render null
|
|
257
|
+
*
|
|
258
|
+
* This prevents hydration mismatches in Next.js SSR by ensuring
|
|
259
|
+
* consistent rendering between server and client initial render.
|
|
260
|
+
*
|
|
245
261
|
* @component
|
|
246
262
|
* @example
|
|
247
263
|
* ```tsx
|
package/dist/components.d.ts
CHANGED
|
@@ -223,6 +223,14 @@ interface ConditionalProps$1 {
|
|
|
223
223
|
/**
|
|
224
224
|
* Conditional component that renders children only when user is signed in.
|
|
225
225
|
*
|
|
226
|
+
* Uses userId to determine rendering:
|
|
227
|
+
* - undefined = not loaded yet (SSR or before hydration) -> render null
|
|
228
|
+
* - null = loaded, user signed out -> render null
|
|
229
|
+
* - string = loaded, user signed in -> render children
|
|
230
|
+
*
|
|
231
|
+
* This prevents hydration mismatches in Next.js SSR by ensuring
|
|
232
|
+
* consistent rendering between server and client initial render.
|
|
233
|
+
*
|
|
226
234
|
* @component
|
|
227
235
|
* @example
|
|
228
236
|
* ```tsx
|
|
@@ -242,6 +250,14 @@ interface ConditionalProps {
|
|
|
242
250
|
/**
|
|
243
251
|
* Conditional component that renders children only when user is signed out.
|
|
244
252
|
*
|
|
253
|
+
* Uses userId to determine rendering:
|
|
254
|
+
* - undefined = not loaded yet (SSR or before hydration) -> render null
|
|
255
|
+
* - null = loaded, user signed out -> render children
|
|
256
|
+
* - string = loaded, user signed in -> render null
|
|
257
|
+
*
|
|
258
|
+
* This prevents hydration mismatches in Next.js SSR by ensuring
|
|
259
|
+
* consistent rendering between server and client initial render.
|
|
260
|
+
*
|
|
245
261
|
* @component
|
|
246
262
|
* @example
|
|
247
263
|
* ```tsx
|
package/dist/components.js
CHANGED
|
@@ -27,9 +27,10 @@ function useInsforge() {
|
|
|
27
27
|
const context = useContext(InsforgeContext);
|
|
28
28
|
if (!context) {
|
|
29
29
|
return {
|
|
30
|
-
user:
|
|
30
|
+
user: void 0,
|
|
31
|
+
userId: void 0,
|
|
31
32
|
isLoaded: false,
|
|
32
|
-
isSignedIn:
|
|
33
|
+
isSignedIn: void 0,
|
|
33
34
|
setUser: () => {
|
|
34
35
|
},
|
|
35
36
|
signIn: () => Promise.resolve({ error: "SSR mode" }),
|
|
@@ -1963,16 +1964,16 @@ function Protect({
|
|
|
1963
1964
|
condition,
|
|
1964
1965
|
onRedirect
|
|
1965
1966
|
}) {
|
|
1966
|
-
const {
|
|
1967
|
+
const { userId, user } = useInsforge();
|
|
1967
1968
|
const resolvedRedirectTo = useMemo(() => resolveAuthPath(redirectTo), [redirectTo]);
|
|
1968
1969
|
useEffect(() => {
|
|
1969
|
-
if (
|
|
1970
|
+
if (userId === null) {
|
|
1970
1971
|
if (onRedirect) {
|
|
1971
1972
|
onRedirect(resolvedRedirectTo);
|
|
1972
1973
|
} else {
|
|
1973
1974
|
window.location.href = resolvedRedirectTo;
|
|
1974
1975
|
}
|
|
1975
|
-
} else if (
|
|
1976
|
+
} else if (userId && condition && user) {
|
|
1976
1977
|
if (!condition(user)) {
|
|
1977
1978
|
if (onRedirect) {
|
|
1978
1979
|
onRedirect(resolvedRedirectTo);
|
|
@@ -1981,11 +1982,11 @@ function Protect({
|
|
|
1981
1982
|
}
|
|
1982
1983
|
}
|
|
1983
1984
|
}
|
|
1984
|
-
}, [
|
|
1985
|
-
if (
|
|
1985
|
+
}, [userId, resolvedRedirectTo, condition, user, onRedirect]);
|
|
1986
|
+
if (userId === void 0) {
|
|
1986
1987
|
return fallback || /* @__PURE__ */ jsx("div", { className: "insforge-loading", children: "Loading..." });
|
|
1987
1988
|
}
|
|
1988
|
-
if (
|
|
1989
|
+
if (userId === null) {
|
|
1989
1990
|
return fallback || null;
|
|
1990
1991
|
}
|
|
1991
1992
|
if (condition && user && !condition(user)) {
|
|
@@ -1994,24 +1995,18 @@ function Protect({
|
|
|
1994
1995
|
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
1995
1996
|
}
|
|
1996
1997
|
function SignedIn({ children }) {
|
|
1997
|
-
const {
|
|
1998
|
-
if (
|
|
1999
|
-
return
|
|
2000
|
-
}
|
|
2001
|
-
if (!isSignedIn) {
|
|
2002
|
-
return null;
|
|
1998
|
+
const { userId } = useInsforge();
|
|
1999
|
+
if (userId) {
|
|
2000
|
+
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
2003
2001
|
}
|
|
2004
|
-
return
|
|
2002
|
+
return null;
|
|
2005
2003
|
}
|
|
2006
2004
|
function SignedOut({ children }) {
|
|
2007
|
-
const {
|
|
2008
|
-
if (
|
|
2009
|
-
return
|
|
2010
|
-
}
|
|
2011
|
-
if (isSignedIn) {
|
|
2012
|
-
return null;
|
|
2005
|
+
const { userId } = useInsforge();
|
|
2006
|
+
if (userId === null) {
|
|
2007
|
+
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
2013
2008
|
}
|
|
2014
|
-
return
|
|
2009
|
+
return null;
|
|
2015
2010
|
}
|
|
2016
2011
|
function SignInButton({ children, className }) {
|
|
2017
2012
|
const { afterSignInUrl, baseUrl } = useInsforge();
|