@insforge/react 0.6.3 → 0.6.5

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.
@@ -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
@@ -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
@@ -27,9 +27,10 @@ function useInsforge() {
27
27
  const context = useContext(InsforgeContext);
28
28
  if (!context) {
29
29
  return {
30
- user: null,
30
+ user: void 0,
31
+ userId: void 0,
31
32
  isLoaded: false,
32
- isSignedIn: false,
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 { isSignedIn, isLoaded, user } = useInsforge();
1967
+ const { userId, user } = useInsforge();
1967
1968
  const resolvedRedirectTo = useMemo(() => resolveAuthPath(redirectTo), [redirectTo]);
1968
1969
  useEffect(() => {
1969
- if (isLoaded && !isSignedIn) {
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 (isLoaded && isSignedIn && condition && user) {
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
- }, [isLoaded, isSignedIn, resolvedRedirectTo, condition, user, onRedirect]);
1985
- if (!isLoaded) {
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 (!isSignedIn) {
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 { isSignedIn, isLoaded } = useInsforge();
1998
- if (!isLoaded) {
1999
- return null;
2000
- }
2001
- if (!isSignedIn) {
2002
- return null;
1998
+ const { userId } = useInsforge();
1999
+ if (userId) {
2000
+ return /* @__PURE__ */ jsx(Fragment, { children });
2003
2001
  }
2004
- return /* @__PURE__ */ jsx(Fragment, { children });
2002
+ return null;
2005
2003
  }
2006
2004
  function SignedOut({ children }) {
2007
- const { isSignedIn, isLoaded } = useInsforge();
2008
- if (!isLoaded) {
2009
- return null;
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 /* @__PURE__ */ jsx(Fragment, { children });
2009
+ return null;
2015
2010
  }
2016
2011
  function SignInButton({ children, className }) {
2017
2012
  const { afterSignInUrl, baseUrl } = useInsforge();