@insforge/react 0.4.6 → 0.4.7

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/forms.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
2
2
  import { AlertTriangle, EyeOff, Eye, Loader2, CircleCheck, Check } from 'lucide-react';
3
- import { createContext, useState, useEffect, useCallback, useContext, useRef } from 'react';
3
+ import { createContext, useState, useEffect, useMemo, useCallback, useContext, useRef } from 'react';
4
4
  import { useSearchParams } from 'react-router-dom';
5
5
  import '@insforge/sdk';
6
6
 
@@ -169,6 +169,28 @@ function createRequirements(config) {
169
169
  }
170
170
  return requirements;
171
171
  }
172
+
173
+ // src/lib/path-utils.ts
174
+ function resolveAuthPath(targetPath) {
175
+ if (typeof window === "undefined") {
176
+ return targetPath;
177
+ }
178
+ const currentPath = window.location.pathname;
179
+ if (currentPath.startsWith("/auth/")) {
180
+ if (targetPath.startsWith("/auth/")) {
181
+ return targetPath;
182
+ }
183
+ return `/auth${targetPath}`;
184
+ }
185
+ return targetPath;
186
+ }
187
+ function resolveAuthUrl(targetPath, searchParams) {
188
+ const resolvedPath = resolveAuthPath(targetPath);
189
+ if (!searchParams || searchParams.toString() === "") {
190
+ return resolvedPath;
191
+ }
192
+ return `${resolvedPath}?${searchParams.toString()}`;
193
+ }
172
194
  function AuthPasswordField({
173
195
  label,
174
196
  id,
@@ -181,6 +203,10 @@ function AuthPasswordField({
181
203
  }) {
182
204
  const [showPassword, setShowPassword] = useState(false);
183
205
  const [showStrength, setShowStrength] = useState(false);
206
+ const resolvedForgotPasswordHref = useMemo(
207
+ () => forgotPasswordLink ? resolveAuthPath(forgotPasswordLink.href) : void 0,
208
+ [forgotPasswordLink]
209
+ );
184
210
  const handleFocus = (e) => {
185
211
  if (showStrengthIndicator) {
186
212
  setShowStrength(true);
@@ -190,7 +216,7 @@ function AuthPasswordField({
190
216
  return /* @__PURE__ */ jsxs("div", { className: "if-passwordField if-internal-p5w9m7", children: [
191
217
  (label || forgotPasswordLink) && /* @__PURE__ */ jsxs("div", { className: "if-passwordField-labelRow", children: [
192
218
  /* @__PURE__ */ jsx("label", { htmlFor: id, className: "if-passwordField-label", children: label }),
193
- forgotPasswordLink && /* @__PURE__ */ jsx("a", { href: forgotPasswordLink.href, className: "if-passwordField-forgotLink", children: forgotPasswordLink.text || "Forget Password?" })
219
+ forgotPasswordLink && resolvedForgotPasswordHref && /* @__PURE__ */ jsx("a", { href: resolvedForgotPasswordHref, className: "if-passwordField-forgotLink", children: forgotPasswordLink.text || "Forget Password?" })
194
220
  ] }),
195
221
  /* @__PURE__ */ jsxs("div", { className: "if-passwordField-inputWrapper", children: [
196
222
  /* @__PURE__ */ jsx(
@@ -243,19 +269,7 @@ function AuthSubmitButton({
243
269
  }
244
270
  function AuthLink({ text, linkText, href }) {
245
271
  const [searchParams] = useSearchParams();
246
- const currentSearch = searchParams.toString();
247
- const finalHref = (() => {
248
- if (!currentSearch) {
249
- return href;
250
- }
251
- try {
252
- const url = new URL(href, window.location.origin);
253
- url.search = currentSearch;
254
- return url.pathname + url.search;
255
- } catch {
256
- return href;
257
- }
258
- })();
272
+ const finalHref = resolveAuthUrl(href, searchParams);
259
273
  return /* @__PURE__ */ jsxs("p", { className: "if-authLink if-internal-al5w9p", children: [
260
274
  text && /* @__PURE__ */ jsx("span", { className: "if-authLink-text", children: text }),
261
275
  text && " ",