@insforge/react 0.4.5 → 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/README.md +4 -1
- package/dist/atoms.cjs +28 -14
- package/dist/atoms.cjs.map +1 -1
- package/dist/atoms.js +29 -15
- package/dist/atoms.js.map +1 -1
- package/dist/components.cjs +36 -24
- package/dist/components.cjs.map +1 -1
- package/dist/components.js +37 -25
- package/dist/components.js.map +1 -1
- package/dist/forms.cjs +28 -14
- package/dist/forms.cjs.map +1 -1
- package/dist/forms.js +29 -15
- package/dist/forms.js.map +1 -1
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +58 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -3
- package/dist/index.d.ts +11 -3
- package/dist/index.js +58 -28
- package/dist/index.js.map +1 -1
- package/dist/lib.cjs +24 -0
- package/dist/lib.cjs.map +1 -1
- package/dist/lib.d.cts +36 -1
- package/dist/lib.d.ts +36 -1
- package/dist/lib.js +23 -1
- package/dist/lib.js.map +1 -1
- package/dist/router.cjs +2 -2
- package/dist/router.cjs.map +1 -1
- package/dist/router.js +2 -2
- package/dist/router.js.map +1 -1
- package/package.json +1 -1
package/dist/lib.cjs
CHANGED
|
@@ -74,10 +74,34 @@ function checkPasswordStrength(password) {
|
|
|
74
74
|
return { score, feedback };
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
// src/lib/path-utils.ts
|
|
78
|
+
function resolveAuthPath(targetPath) {
|
|
79
|
+
if (typeof window === "undefined") {
|
|
80
|
+
return targetPath;
|
|
81
|
+
}
|
|
82
|
+
const currentPath = window.location.pathname;
|
|
83
|
+
if (currentPath.startsWith("/auth/")) {
|
|
84
|
+
if (targetPath.startsWith("/auth/")) {
|
|
85
|
+
return targetPath;
|
|
86
|
+
}
|
|
87
|
+
return `/auth${targetPath}`;
|
|
88
|
+
}
|
|
89
|
+
return targetPath;
|
|
90
|
+
}
|
|
91
|
+
function resolveAuthUrl(targetPath, searchParams) {
|
|
92
|
+
const resolvedPath = resolveAuthPath(targetPath);
|
|
93
|
+
if (!searchParams || searchParams.toString() === "") {
|
|
94
|
+
return resolvedPath;
|
|
95
|
+
}
|
|
96
|
+
return `${resolvedPath}?${searchParams.toString()}`;
|
|
97
|
+
}
|
|
98
|
+
|
|
77
99
|
exports.checkPasswordStrength = checkPasswordStrength;
|
|
78
100
|
exports.createPasswordSchema = createPasswordSchema;
|
|
79
101
|
exports.emailSchema = emailSchema;
|
|
80
102
|
exports.passwordSchema = passwordSchema;
|
|
103
|
+
exports.resolveAuthPath = resolveAuthPath;
|
|
104
|
+
exports.resolveAuthUrl = resolveAuthUrl;
|
|
81
105
|
exports.validateEmail = validateEmail;
|
|
82
106
|
exports.validatePassword = validatePassword;
|
|
83
107
|
//# sourceMappingURL=lib.cjs.map
|
package/dist/lib.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/lib/validation.ts"],"names":["z"],"mappings":";;;;AAKO,IAAM,WAAA,GAAcA,MAAE,MAAA,EAAO,CAAE,IAAI,CAAA,EAAG,mBAAmB,CAAA,CAAE,KAAA,CAAM,uBAAuB;AAKxF,SAAS,qBAAqB,OAAA,EAMlC;AACD,EAAA,MAAM;AAAA,IACJ,SAAA,GAAY,CAAA;AAAA,IACZ,gBAAA,GAAmB,KAAA;AAAA,IACnB,gBAAA,GAAmB,KAAA;AAAA,IACnB,aAAA,GAAgB,KAAA;AAAA,IAChB,kBAAA,GAAqB;AAAA,GACvB,GAAI,WAAW,EAAC;AAEhB,EAAA,IAAI,MAAA,GAASA,MAAE,MAAA,EAAO,CAAE,IAAI,SAAA,EAAW,CAAA,0BAAA,EAA6B,SAAS,CAAA,WAAA,CAAa,CAAA;AAE1F,EAAA,IAAI,gBAAA,EAAkB;AACpB,IAAA,MAAA,GAAS,MAAA,CAAO,KAAA,CAAM,OAAA,EAAS,qDAAqD,CAAA;A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IAAS,CAAA;AAAA,EACX,CAAA,MAAO;AACL,IAAA,QAAA,CAAS,KAAK,2BAA2B,CAAA;AAAA,EAC3C;AAEA,EAAA,IAAI,QAAA,CAAS,UAAU,EAAA,EAAI;AACzB,IAAA,KAAA,IAAS,CAAA;AAAA,EACX;AAEA,EAAA,IAAI,QAAQ,IAAA,CAAK,QAAQ,KAAK,OAAA,CAAQ,IAAA,CAAK,QAAQ,CAAA,EAAG;AACpD,IAAA,KAAA,IAAS,CAAA;AAAA,EACX,CAAA,MAAO;AACL,IAAA,QAAA,CAAS,KAAK,0CAA0C,CAAA;AAAA,EAC1D;AAEA,EAAA,IAAI,IAAA,CAAK,IAAA,CAAK,QAAQ,CAAA,EAAG;AACvB,IAAA,KAAA,IAAS,CAAA;AAAA,EACX,CAAA,MAAO;AACL,IAAA,QAAA,CAAS,KAAK,6BAA6B,CAAA;AAAA,EAC7C;AAEA,EAAA,IAAI,qCAAA,CAAsC,IAAA,CAAK,QAAQ,CAAA,EAAG;AACxD,IAAA,KAAA,IAAS,CAAA;AAAA,EACX,CAAA,MAAO;AACL,IAAA,QAAA,CAAS,KAAK,wCAAwC,CAAA;AAAA,EACxD;AAEA,EAAA,OAAO,EAAE,OAAO,QAAA,EAAS;AAC3B","file":"lib.cjs","sourcesContent":["import { z } from 'zod';\n\n/**\n * Email validation schema\n */\nexport const emailSchema = z.string().min(1, 'Email is required').email('Invalid email address');\n\n/**\n * Password validation schema with configurable requirements\n */\nexport function createPasswordSchema(options?: {\n minLength?: number;\n requireUppercase?: boolean;\n requireLowercase?: boolean;\n requireNumber?: boolean;\n requireSpecialChar?: boolean;\n}) {\n const {\n minLength = 6,\n requireUppercase = false,\n requireLowercase = false,\n requireNumber = false,\n requireSpecialChar = false,\n } = options || {};\n\n let schema = z.string().min(minLength, `Password must be at least ${minLength} characters`);\n\n if (requireUppercase) {\n schema = schema.regex(/[A-Z]/, 'Password must contain at least one uppercase letter');\n }\n\n if (requireLowercase) {\n schema = schema.regex(/[a-z]/, 'Password must contain at least one lowercase letter');\n }\n\n if (requireNumber) {\n schema = schema.regex(/\\d/, 'Password must contain at least one number');\n }\n\n if (requireSpecialChar) {\n schema = schema.regex(\n /[!@#$%^&*()_+\\-=[\\]{};':\"\\\\|,.<>/?]/,\n 'Password must contain at least one special character'\n );\n }\n\n return schema;\n}\n\n/**\n * Default password schema (minimum 6 characters)\n */\nexport const passwordSchema = createPasswordSchema();\n\n/**\n * Validate email format\n */\nexport function validateEmail(email: string): { valid: boolean; error?: string } {\n const result = emailSchema.safeParse(email);\n if (result.success) {\n return { valid: true };\n }\n return { valid: false, error: result.error.message };\n}\n\n/**\n * Validate password format\n */\nexport function validatePassword(\n password: string,\n options?: Parameters<typeof createPasswordSchema>[0]\n): { valid: boolean; error?: string } {\n const schema = createPasswordSchema(options);\n const result = schema.safeParse(password);\n if (result.success) {\n return { valid: true };\n }\n return { valid: false, error: result.error.message };\n}\n\n/**\n * Validate password strength based on multiple criteria\n */\nexport function checkPasswordStrength(password: string): {\n score: number;\n feedback: string[];\n} {\n const feedback: string[] = [];\n let score = 0;\n\n if (password.length >= 8) {\n score += 1;\n } else {\n feedback.push('Use at least 8 characters');\n }\n\n if (password.length >= 12) {\n score += 1;\n }\n\n if (/[a-z]/.test(password) && /[A-Z]/.test(password)) {\n score += 1;\n } else {\n feedback.push('Use both uppercase and lowercase letters');\n }\n\n if (/\\d/.test(password)) {\n score += 1;\n } else {\n feedback.push('Include at least one number');\n }\n\n if (/[!@#$%^&*()_+\\-=[\\]{};':\"\\\\|,.<>/?]/.test(password)) {\n score += 1;\n } else {\n feedback.push('Include at least one special character');\n }\n\n return { score, feedback };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/lib/validation.ts","../src/lib/path-utils.ts"],"names":["z"],"mappings":";;;;AAKO,IAAM,WAAA,GAAcA,MAAE,MAAA,EAAO,CAAE,IAAI,CAAA,EAAG,mBAAmB,CAAA,CAAE,KAAA,CAAM,uBAAuB;AAKxF,SAAS,qBA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ClGO,SAAS,gBAAgB,UAAA,EAA4B;AAC1D,EAAA,IAAI,OAAO,WAAW,WAAA,EAAa;AACjC,IAAA,OAAO,UAAA;AAAA,EACT;AAEA,EAAA,MAAM,WAAA,GAAc,OAAO,QAAA,CAAS,QAAA;AAGpC,EAAA,IAAI,WAAA,CAAY,UAAA,CAAW,QAAQ,CAAA,EAAG;AAEpC,IAAA,IAAI,UAAA,CAAW,UAAA,CAAW,QAAQ,CAAA,EAAG;AACnC,MAAA,OAAO,UAAA;AAAA,IACT;AAEA,IAAA,OAAO,QAAQ,UAAU,CAAA,CAAA;AAAA,EAC3B;AAGA,EAAA,OAAO,UAAA;AACT;AAcO,SAAS,cAAA,CAAe,YAAoB,YAAA,EAAwC;AACzF,EAAA,MAAM,YAAA,GAAe,gBAAgB,UAAU,CAAA;AAE/C,EAAA,IAAI,CAAC,YAAA,IAAgB,YAAA,CAAa,QAAA,OAAe,EAAA,EAAI;AACnD,IAAA,OAAO,YAAA;AAAA,EACT;AAEA,EAAA,OAAO,CAAA,EAAG,YAAY,CAAA,CAAA,EAAI,YAAA,CAAa,UAAU,CAAA,CAAA;AACnD","file":"lib.cjs","sourcesContent":["import { z } from 'zod';\n\n/**\n * Email validation schema\n */\nexport const emailSchema = z.string().min(1, 'Email is required').email('Invalid email address');\n\n/**\n * Password validation schema with configurable requirements\n */\nexport function createPasswordSchema(options?: {\n minLength?: number;\n requireUppercase?: boolean;\n requireLowercase?: boolean;\n requireNumber?: boolean;\n requireSpecialChar?: boolean;\n}) {\n const {\n minLength = 6,\n requireUppercase = false,\n requireLowercase = false,\n requireNumber = false,\n requireSpecialChar = false,\n } = options || {};\n\n let schema = z.string().min(minLength, `Password must be at least ${minLength} characters`);\n\n if (requireUppercase) {\n schema = schema.regex(/[A-Z]/, 'Password must contain at least one uppercase letter');\n }\n\n if (requireLowercase) {\n schema = schema.regex(/[a-z]/, 'Password must contain at least one lowercase letter');\n }\n\n if (requireNumber) {\n schema = schema.regex(/\\d/, 'Password must contain at least one number');\n }\n\n if (requireSpecialChar) {\n schema = schema.regex(\n /[!@#$%^&*()_+\\-=[\\]{};':\"\\\\|,.<>/?]/,\n 'Password must contain at least one special character'\n );\n }\n\n return schema;\n}\n\n/**\n * Default password schema (minimum 6 characters)\n */\nexport const passwordSchema = createPasswordSchema();\n\n/**\n * Validate email format\n */\nexport function validateEmail(email: string): { valid: boolean; error?: string } {\n const result = emailSchema.safeParse(email);\n if (result.success) {\n return { valid: true };\n }\n return { valid: false, error: result.error.message };\n}\n\n/**\n * Validate password format\n */\nexport function validatePassword(\n password: string,\n options?: Parameters<typeof createPasswordSchema>[0]\n): { valid: boolean; error?: string } {\n const schema = createPasswordSchema(options);\n const result = schema.safeParse(password);\n if (result.success) {\n return { valid: true };\n }\n return { valid: false, error: result.error.message };\n}\n\n/**\n * Validate password strength based on multiple criteria\n */\nexport function checkPasswordStrength(password: string): {\n score: number;\n feedback: string[];\n} {\n const feedback: string[] = [];\n let score = 0;\n\n if (password.length >= 8) {\n score += 1;\n } else {\n feedback.push('Use at least 8 characters');\n }\n\n if (password.length >= 12) {\n score += 1;\n }\n\n if (/[a-z]/.test(password) && /[A-Z]/.test(password)) {\n score += 1;\n } else {\n feedback.push('Use both uppercase and lowercase letters');\n }\n\n if (/\\d/.test(password)) {\n score += 1;\n } else {\n feedback.push('Include at least one number');\n }\n\n if (/[!@#$%^&*()_+\\-=[\\]{};':\"\\\\|,.<>/?]/.test(password)) {\n score += 1;\n } else {\n feedback.push('Include at least one special character');\n }\n\n return { score, feedback };\n}\n","/**\n * Path utilities for handling navigation in auth flows.\n * Ensures proper path resolution when auth pages are served under a base path (e.g., /auth/)\n */\n\n/**\n * Resolves an auth route path relative to the current location.\n * If the current path is under /auth/, it will preserve that prefix.\n * Otherwise, it returns the path as-is.\n *\n * @param targetPath - The target auth path (e.g., '/sign-in', '/sign-up')\n * @returns The resolved path with proper base path handling\n *\n * @example\n * // Current URL: http://localhost:5174/auth/sign-in\n * resolveAuthPath('/sign-up') // Returns '/auth/sign-up'\n *\n * @example\n * // Current URL: http://localhost:5174/sign-in\n * resolveAuthPath('/sign-up') // Returns '/sign-up'\n */\nexport function resolveAuthPath(targetPath: string): string {\n if (typeof window === 'undefined') {\n return targetPath;\n }\n\n const currentPath = window.location.pathname;\n\n // Check if we're currently under /auth/ base path\n if (currentPath.startsWith('/auth/')) {\n // If target already has /auth/ prefix, return as-is\n if (targetPath.startsWith('/auth/')) {\n return targetPath;\n }\n // Add /auth/ prefix to the target path\n return `/auth${targetPath}`;\n }\n\n // Not under /auth/, return target path as-is\n return targetPath;\n}\n\n/**\n * Resolves an auth route URL with search params preserved.\n * Similar to resolveAuthPath but returns a full URL string with query parameters.\n *\n * @param targetPath - The target auth path (e.g., '/sign-in', '/sign-up')\n * @param searchParams - Optional URLSearchParams to append\n * @returns The resolved URL as a string\n *\n * @example\n * // Current URL: http://localhost:5174/auth/sign-in?redirect=...\n * resolveAuthUrl('/sign-up', searchParams) // Returns '/auth/sign-up?redirect=...'\n */\nexport function resolveAuthUrl(targetPath: string, searchParams?: URLSearchParams): string {\n const resolvedPath = resolveAuthPath(targetPath);\n\n if (!searchParams || searchParams.toString() === '') {\n return resolvedPath;\n }\n\n return `${resolvedPath}?${searchParams.toString()}`;\n}\n"]}
|
package/dist/lib.d.cts
CHANGED
|
@@ -40,4 +40,39 @@ declare function checkPasswordStrength(password: string): {
|
|
|
40
40
|
feedback: string[];
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Path utilities for handling navigation in auth flows.
|
|
45
|
+
* Ensures proper path resolution when auth pages are served under a base path (e.g., /auth/)
|
|
46
|
+
*/
|
|
47
|
+
/**
|
|
48
|
+
* Resolves an auth route path relative to the current location.
|
|
49
|
+
* If the current path is under /auth/, it will preserve that prefix.
|
|
50
|
+
* Otherwise, it returns the path as-is.
|
|
51
|
+
*
|
|
52
|
+
* @param targetPath - The target auth path (e.g., '/sign-in', '/sign-up')
|
|
53
|
+
* @returns The resolved path with proper base path handling
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* // Current URL: http://localhost:5174/auth/sign-in
|
|
57
|
+
* resolveAuthPath('/sign-up') // Returns '/auth/sign-up'
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* // Current URL: http://localhost:5174/sign-in
|
|
61
|
+
* resolveAuthPath('/sign-up') // Returns '/sign-up'
|
|
62
|
+
*/
|
|
63
|
+
declare function resolveAuthPath(targetPath: string): string;
|
|
64
|
+
/**
|
|
65
|
+
* Resolves an auth route URL with search params preserved.
|
|
66
|
+
* Similar to resolveAuthPath but returns a full URL string with query parameters.
|
|
67
|
+
*
|
|
68
|
+
* @param targetPath - The target auth path (e.g., '/sign-in', '/sign-up')
|
|
69
|
+
* @param searchParams - Optional URLSearchParams to append
|
|
70
|
+
* @returns The resolved URL as a string
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* // Current URL: http://localhost:5174/auth/sign-in?redirect=...
|
|
74
|
+
* resolveAuthUrl('/sign-up', searchParams) // Returns '/auth/sign-up?redirect=...'
|
|
75
|
+
*/
|
|
76
|
+
declare function resolveAuthUrl(targetPath: string, searchParams?: URLSearchParams): string;
|
|
77
|
+
|
|
78
|
+
export { checkPasswordStrength, createPasswordSchema, emailSchema, passwordSchema, resolveAuthPath, resolveAuthUrl, validateEmail, validatePassword };
|
package/dist/lib.d.ts
CHANGED
|
@@ -40,4 +40,39 @@ declare function checkPasswordStrength(password: string): {
|
|
|
40
40
|
feedback: string[];
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Path utilities for handling navigation in auth flows.
|
|
45
|
+
* Ensures proper path resolution when auth pages are served under a base path (e.g., /auth/)
|
|
46
|
+
*/
|
|
47
|
+
/**
|
|
48
|
+
* Resolves an auth route path relative to the current location.
|
|
49
|
+
* If the current path is under /auth/, it will preserve that prefix.
|
|
50
|
+
* Otherwise, it returns the path as-is.
|
|
51
|
+
*
|
|
52
|
+
* @param targetPath - The target auth path (e.g., '/sign-in', '/sign-up')
|
|
53
|
+
* @returns The resolved path with proper base path handling
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* // Current URL: http://localhost:5174/auth/sign-in
|
|
57
|
+
* resolveAuthPath('/sign-up') // Returns '/auth/sign-up'
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* // Current URL: http://localhost:5174/sign-in
|
|
61
|
+
* resolveAuthPath('/sign-up') // Returns '/sign-up'
|
|
62
|
+
*/
|
|
63
|
+
declare function resolveAuthPath(targetPath: string): string;
|
|
64
|
+
/**
|
|
65
|
+
* Resolves an auth route URL with search params preserved.
|
|
66
|
+
* Similar to resolveAuthPath but returns a full URL string with query parameters.
|
|
67
|
+
*
|
|
68
|
+
* @param targetPath - The target auth path (e.g., '/sign-in', '/sign-up')
|
|
69
|
+
* @param searchParams - Optional URLSearchParams to append
|
|
70
|
+
* @returns The resolved URL as a string
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* // Current URL: http://localhost:5174/auth/sign-in?redirect=...
|
|
74
|
+
* resolveAuthUrl('/sign-up', searchParams) // Returns '/auth/sign-up?redirect=...'
|
|
75
|
+
*/
|
|
76
|
+
declare function resolveAuthUrl(targetPath: string, searchParams?: URLSearchParams): string;
|
|
77
|
+
|
|
78
|
+
export { checkPasswordStrength, createPasswordSchema, emailSchema, passwordSchema, resolveAuthPath, resolveAuthUrl, validateEmail, validatePassword };
|
package/dist/lib.js
CHANGED
|
@@ -72,6 +72,28 @@ function checkPasswordStrength(password) {
|
|
|
72
72
|
return { score, feedback };
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
// src/lib/path-utils.ts
|
|
76
|
+
function resolveAuthPath(targetPath) {
|
|
77
|
+
if (typeof window === "undefined") {
|
|
78
|
+
return targetPath;
|
|
79
|
+
}
|
|
80
|
+
const currentPath = window.location.pathname;
|
|
81
|
+
if (currentPath.startsWith("/auth/")) {
|
|
82
|
+
if (targetPath.startsWith("/auth/")) {
|
|
83
|
+
return targetPath;
|
|
84
|
+
}
|
|
85
|
+
return `/auth${targetPath}`;
|
|
86
|
+
}
|
|
87
|
+
return targetPath;
|
|
88
|
+
}
|
|
89
|
+
function resolveAuthUrl(targetPath, searchParams) {
|
|
90
|
+
const resolvedPath = resolveAuthPath(targetPath);
|
|
91
|
+
if (!searchParams || searchParams.toString() === "") {
|
|
92
|
+
return resolvedPath;
|
|
93
|
+
}
|
|
94
|
+
return `${resolvedPath}?${searchParams.toString()}`;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export { checkPasswordStrength, createPasswordSchema, emailSchema, passwordSchema, resolveAuthPath, resolveAuthUrl, validateEmail, validatePassword };
|
|
76
98
|
//# sourceMappingURL=lib.js.map
|
|
77
99
|
//# sourceMappingURL=lib.js.map
|
package/dist/lib.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/lib/validation.ts"],"names":[],"mappings":";;AAKO,IAAM,WAAA,GAAc,EAAE,MAAA,EAAO,CAAE,IAAI,CAAA,EAAG,mBAAmB,CAAA,CAAE,KAAA,CAAM,uBAAuB;AAKxF,SAAS,qBAAqB,OAAA,EAMlC;AACD,EAAA,MAAM;AAAA,IACJ,SAAA,GAAY,CAAA;AAAA,IACZ,gBAAA,GAAmB,KAAA;AAAA,IACnB,gBAAA,GAAmB,KAAA;AAAA,IACnB,aAAA,GAAgB,KAAA;AAAA,IAChB,kBAAA,GAAqB;AAAA,GACvB,GAAI,WAAW,EAAC;AAEhB,EAAA,IAAI,MAAA,GAAS,EAAE,MAAA,EAAO,CAAE,IAAI,SAAA,EAAW,CAAA,0BAAA,EAA6B,SAAS,CAAA,WAAA,CAAa,CAAA;AAE1F,EAAA,IAAI,gBAAA,EAAkB;AACpB,IAAA,MAAA,GAAS,MAAA,CAAO,KAAA,CAAM,OAAA,EAAS,qDAAqD,CAAA;AAAA,EAC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AAA;AAAA,EACX,CAAA,MAAO;AACL,IAAA,QAAA,CAAS,KAAK,2BAA2B,CAAA;AAAA,EAC3C;AAEA,EAAA,IAAI,QAAA,CAAS,UAAU,EAAA,EAAI;AACzB,IAAA,KAAA,IAAS,CAAA;AAAA,EACX;AAEA,EAAA,IAAI,QAAQ,IAAA,CAAK,QAAQ,KAAK,OAAA,CAAQ,IAAA,CAAK,QAAQ,CAAA,EAAG;AACpD,IAAA,KAAA,IAAS,CAAA;AAAA,EACX,CAAA,MAAO;AACL,IAAA,QAAA,CAAS,KAAK,0CAA0C,CAAA;AAAA,EAC1D;AAEA,EAAA,IAAI,IAAA,CAAK,IAAA,CAAK,QAAQ,CAAA,EAAG;AACvB,IAAA,KAAA,IAAS,CAAA;AAAA,EACX,CAAA,MAAO;AACL,IAAA,QAAA,CAAS,KAAK,6BAA6B,CAAA;AAAA,EAC7C;AAEA,EAAA,IAAI,qCAAA,CAAsC,IAAA,CAAK,QAAQ,CAAA,EAAG;AACxD,IAAA,KAAA,IAAS,CAAA;AAAA,EACX,CAAA,MAAO;AACL,IAAA,QAAA,CAAS,KAAK,wCAAwC,CAAA;AAAA,EACxD;AAEA,EAAA,OAAO,EAAE,OAAO,QAAA,EAAS;AAC3B","file":"lib.js","sourcesContent":["import { z } from 'zod';\n\n/**\n * Email validation schema\n */\nexport const emailSchema = z.string().min(1, 'Email is required').email('Invalid email address');\n\n/**\n * Password validation schema with configurable requirements\n */\nexport function createPasswordSchema(options?: {\n minLength?: number;\n requireUppercase?: boolean;\n requireLowercase?: boolean;\n requireNumber?: boolean;\n requireSpecialChar?: boolean;\n}) {\n const {\n minLength = 6,\n requireUppercase = false,\n requireLowercase = false,\n requireNumber = false,\n requireSpecialChar = false,\n } = options || {};\n\n let schema = z.string().min(minLength, `Password must be at least ${minLength} characters`);\n\n if (requireUppercase) {\n schema = schema.regex(/[A-Z]/, 'Password must contain at least one uppercase letter');\n }\n\n if (requireLowercase) {\n schema = schema.regex(/[a-z]/, 'Password must contain at least one lowercase letter');\n }\n\n if (requireNumber) {\n schema = schema.regex(/\\d/, 'Password must contain at least one number');\n }\n\n if (requireSpecialChar) {\n schema = schema.regex(\n /[!@#$%^&*()_+\\-=[\\]{};':\"\\\\|,.<>/?]/,\n 'Password must contain at least one special character'\n );\n }\n\n return schema;\n}\n\n/**\n * Default password schema (minimum 6 characters)\n */\nexport const passwordSchema = createPasswordSchema();\n\n/**\n * Validate email format\n */\nexport function validateEmail(email: string): { valid: boolean; error?: string } {\n const result = emailSchema.safeParse(email);\n if (result.success) {\n return { valid: true };\n }\n return { valid: false, error: result.error.message };\n}\n\n/**\n * Validate password format\n */\nexport function validatePassword(\n password: string,\n options?: Parameters<typeof createPasswordSchema>[0]\n): { valid: boolean; error?: string } {\n const schema = createPasswordSchema(options);\n const result = schema.safeParse(password);\n if (result.success) {\n return { valid: true };\n }\n return { valid: false, error: result.error.message };\n}\n\n/**\n * Validate password strength based on multiple criteria\n */\nexport function checkPasswordStrength(password: string): {\n score: number;\n feedback: string[];\n} {\n const feedback: string[] = [];\n let score = 0;\n\n if (password.length >= 8) {\n score += 1;\n } else {\n feedback.push('Use at least 8 characters');\n }\n\n if (password.length >= 12) {\n score += 1;\n }\n\n if (/[a-z]/.test(password) && /[A-Z]/.test(password)) {\n score += 1;\n } else {\n feedback.push('Use both uppercase and lowercase letters');\n }\n\n if (/\\d/.test(password)) {\n score += 1;\n } else {\n feedback.push('Include at least one number');\n }\n\n if (/[!@#$%^&*()_+\\-=[\\]{};':\"\\\\|,.<>/?]/.test(password)) {\n score += 1;\n } else {\n feedback.push('Include at least one special character');\n }\n\n return { score, feedback };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/lib/validation.ts","../src/lib/path-utils.ts"],"names":[],"mappings":";;AAKO,IAAM,WAAA,GAAc,EAAE,MAAA,EAAO,CAAE,IAAI,CAAA,EAAG,mBAAmB,CAAA,CAAE,KAAA,CAAM,uBAAuB;AAKxF,SAAS,qBAAqB,OAAA,EAMl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gB,UAAA,EAA4B;AAC1D,EAAA,IAAI,OAAO,WAAW,WAAA,EAAa;AACjC,IAAA,OAAO,UAAA;AAAA,EACT;AAEA,EAAA,MAAM,WAAA,GAAc,OAAO,QAAA,CAAS,QAAA;AAGpC,EAAA,IAAI,WAAA,CAAY,UAAA,CAAW,QAAQ,CAAA,EAAG;AAEpC,IAAA,IAAI,UAAA,CAAW,UAAA,CAAW,QAAQ,CAAA,EAAG;AACnC,MAAA,OAAO,UAAA;AAAA,IACT;AAEA,IAAA,OAAO,QAAQ,UAAU,CAAA,CAAA;AAAA,EAC3B;AAGA,EAAA,OAAO,UAAA;AACT;AAcO,SAAS,cAAA,CAAe,YAAoB,YAAA,EAAwC;AACzF,EAAA,MAAM,YAAA,GAAe,gBAAgB,UAAU,CAAA;AAE/C,EAAA,IAAI,CAAC,YAAA,IAAgB,YAAA,CAAa,QAAA,OAAe,EAAA,EAAI;AACnD,IAAA,OAAO,YAAA;AAAA,EACT;AAEA,EAAA,OAAO,CAAA,EAAG,YAAY,CAAA,CAAA,EAAI,YAAA,CAAa,UAAU,CAAA,CAAA;AACnD","file":"lib.js","sourcesContent":["import { z } from 'zod';\n\n/**\n * Email validation schema\n */\nexport const emailSchema = z.string().min(1, 'Email is required').email('Invalid email address');\n\n/**\n * Password validation schema with configurable requirements\n */\nexport function createPasswordSchema(options?: {\n minLength?: number;\n requireUppercase?: boolean;\n requireLowercase?: boolean;\n requireNumber?: boolean;\n requireSpecialChar?: boolean;\n}) {\n const {\n minLength = 6,\n requireUppercase = false,\n requireLowercase = false,\n requireNumber = false,\n requireSpecialChar = false,\n } = options || {};\n\n let schema = z.string().min(minLength, `Password must be at least ${minLength} characters`);\n\n if (requireUppercase) {\n schema = schema.regex(/[A-Z]/, 'Password must contain at least one uppercase letter');\n }\n\n if (requireLowercase) {\n schema = schema.regex(/[a-z]/, 'Password must contain at least one lowercase letter');\n }\n\n if (requireNumber) {\n schema = schema.regex(/\\d/, 'Password must contain at least one number');\n }\n\n if (requireSpecialChar) {\n schema = schema.regex(\n /[!@#$%^&*()_+\\-=[\\]{};':\"\\\\|,.<>/?]/,\n 'Password must contain at least one special character'\n );\n }\n\n return schema;\n}\n\n/**\n * Default password schema (minimum 6 characters)\n */\nexport const passwordSchema = createPasswordSchema();\n\n/**\n * Validate email format\n */\nexport function validateEmail(email: string): { valid: boolean; error?: string } {\n const result = emailSchema.safeParse(email);\n if (result.success) {\n return { valid: true };\n }\n return { valid: false, error: result.error.message };\n}\n\n/**\n * Validate password format\n */\nexport function validatePassword(\n password: string,\n options?: Parameters<typeof createPasswordSchema>[0]\n): { valid: boolean; error?: string } {\n const schema = createPasswordSchema(options);\n const result = schema.safeParse(password);\n if (result.success) {\n return { valid: true };\n }\n return { valid: false, error: result.error.message };\n}\n\n/**\n * Validate password strength based on multiple criteria\n */\nexport function checkPasswordStrength(password: string): {\n score: number;\n feedback: string[];\n} {\n const feedback: string[] = [];\n let score = 0;\n\n if (password.length >= 8) {\n score += 1;\n } else {\n feedback.push('Use at least 8 characters');\n }\n\n if (password.length >= 12) {\n score += 1;\n }\n\n if (/[a-z]/.test(password) && /[A-Z]/.test(password)) {\n score += 1;\n } else {\n feedback.push('Use both uppercase and lowercase letters');\n }\n\n if (/\\d/.test(password)) {\n score += 1;\n } else {\n feedback.push('Include at least one number');\n }\n\n if (/[!@#$%^&*()_+\\-=[\\]{};':\"\\\\|,.<>/?]/.test(password)) {\n score += 1;\n } else {\n feedback.push('Include at least one special character');\n }\n\n return { score, feedback };\n}\n","/**\n * Path utilities for handling navigation in auth flows.\n * Ensures proper path resolution when auth pages are served under a base path (e.g., /auth/)\n */\n\n/**\n * Resolves an auth route path relative to the current location.\n * If the current path is under /auth/, it will preserve that prefix.\n * Otherwise, it returns the path as-is.\n *\n * @param targetPath - The target auth path (e.g., '/sign-in', '/sign-up')\n * @returns The resolved path with proper base path handling\n *\n * @example\n * // Current URL: http://localhost:5174/auth/sign-in\n * resolveAuthPath('/sign-up') // Returns '/auth/sign-up'\n *\n * @example\n * // Current URL: http://localhost:5174/sign-in\n * resolveAuthPath('/sign-up') // Returns '/sign-up'\n */\nexport function resolveAuthPath(targetPath: string): string {\n if (typeof window === 'undefined') {\n return targetPath;\n }\n\n const currentPath = window.location.pathname;\n\n // Check if we're currently under /auth/ base path\n if (currentPath.startsWith('/auth/')) {\n // If target already has /auth/ prefix, return as-is\n if (targetPath.startsWith('/auth/')) {\n return targetPath;\n }\n // Add /auth/ prefix to the target path\n return `/auth${targetPath}`;\n }\n\n // Not under /auth/, return target path as-is\n return targetPath;\n}\n\n/**\n * Resolves an auth route URL with search params preserved.\n * Similar to resolveAuthPath but returns a full URL string with query parameters.\n *\n * @param targetPath - The target auth path (e.g., '/sign-in', '/sign-up')\n * @param searchParams - Optional URLSearchParams to append\n * @returns The resolved URL as a string\n *\n * @example\n * // Current URL: http://localhost:5174/auth/sign-in?redirect=...\n * resolveAuthUrl('/sign-up', searchParams) // Returns '/auth/sign-up?redirect=...'\n */\nexport function resolveAuthUrl(targetPath: string, searchParams?: URLSearchParams): string {\n const resolvedPath = resolveAuthPath(targetPath);\n\n if (!searchParams || searchParams.toString() === '') {\n return resolvedPath;\n }\n\n return `${resolvedPath}?${searchParams.toString()}`;\n}\n"]}
|
package/dist/router.cjs
CHANGED
|
@@ -5,9 +5,9 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
5
5
|
|
|
6
6
|
function RedirectToAuth({ baseUrl, path }) {
|
|
7
7
|
react.useEffect(() => {
|
|
8
|
-
const
|
|
8
|
+
const currentUrl = window.location.href;
|
|
9
9
|
const authUrl = new URL(path, baseUrl);
|
|
10
|
-
authUrl.searchParams.set("redirect",
|
|
10
|
+
authUrl.searchParams.set("redirect", currentUrl);
|
|
11
11
|
window.location.replace(authUrl.toString());
|
|
12
12
|
}, [baseUrl, path]);
|
|
13
13
|
return null;
|
package/dist/router.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/router/getInsforgeRoutes.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,QACE,IAAA,EAAM,MAAA;AAAA,QACN,OAAA,kBAASA,cAAA,CAAC,cAAA,EAAA,EAAe,OAAA,EAAkB,MAAK,eAAA,EAAgB;AAAA,OAClE;AAAA,MACA;AAAA,QACE,IAAA,EAAM,WAAA;AAAA,QACN,OAAA,kBAASA,cAAA,CAAC,cAAA,EAAA,EAAe,OAAA,EAAkB,MAAK,oBAAA,EAAqB;AAAA,OACvE;AAAA,MACA;AAAA,QACE,IAAA,EAAM,cAAA;AAAA,QACN,OAAA,kBAASA,cAAA,CAAC,cAAA,EAAA,EAAe,OAAA,EAAkB,MAAK,uBAAA,EAAwB;AAAA,OAC1E;AAAA,MACA;AAAA,QACE,IAAA,EAAM,aAAA;AAAA,QACN,OAAA,kBAASA,cAAA,CAAC,cAAA,EAAA,EAAe,OAAA,EAAkB,MAAK,sBAAA,EAAuB;AAAA;AACzE,KACF;AAAA,EACF;AAEA,EAAA,OAAO,MAAA;AACT","file":"router.cjs","sourcesContent":["'use client';\n\nimport { useEffect } from 'react';\nimport type { RouteObject } from 'react-router-dom';\n\ninterface GetInsforgeRoutesConfig {\n /**\n * Base URL of your Insforge backend\n */\n baseUrl: string;\n\n /**\n * Whether to use built-in auth (deployed Insforge Auth)\n * When true: redirects to baseUrl/auth/* pages\n * When false: no redirect routes are added (use your own components)\n * @default true\n */\n builtInAuth?: boolean;\n\n /**\n * Custom paths for auth redirect routes\n * @default {\n * signIn: '/sign-in',\n * signUp: '/sign-up',\n * verifyEmail: '/verify-email',\n * forgotPassword: '/forgot-password',\n * resetPassword: '/reset-password'\n * }\n */\n paths?: {\n signIn?: string;\n signUp?: string;\n verifyEmail?: string;\n forgotPassword?: string;\n resetPassword?: string;\n };\n}\n\n/**\n * Helper component for redirecting to external auth\n */\nfunction RedirectToAuth({ baseUrl, path }: { baseUrl: string; path: string }) {\n useEffect(() => {\n // Redirect back to current URL - middleware/SDK will handle token from URL\n const currentUrl = window.location.href;\n const authUrl = new URL(path, baseUrl);\n authUrl.searchParams.set('redirect', currentUrl);\n window.location.replace(authUrl.toString());\n }, [baseUrl, path]);\n\n return null;\n}\n\n/**\n * Generates Insforge authentication redirect routes for React Router.\n *\n * Returns redirect routes for sign-in, sign-up, etc. that redirect to your deployed Insforge auth pages.\n *\n * @param config - Configuration for Insforge routes\n * @returns Array of RouteObject for React Router (redirect routes only)\n *\n * @example\n * ```tsx\n * import { createBrowserRouter } from 'react-router-dom';\n * import { getInsforgeRoutes } from '@insforge/react/router';\n *\n * const router = createBrowserRouter([\n * {\n * path: '/',\n * element: <Layout />,\n * children: [\n * { index: true, element: <Home /> },\n * { path: 'dashboard', element: <Dashboard /> }\n * ]\n * },\n * // Add redirect routes (sign-in, sign-up, etc.)\n * ...getInsforgeRoutes({\n * baseUrl: 'https://your-backend.com',\n * builtInAuth: true\n * })\n * ]);\n * ```\n *\n * @example\n * ```tsx\n * // Custom paths for redirect routes\n * ...getInsforgeRoutes({\n * baseUrl: 'https://your-backend.com',\n * builtInAuth: true,\n * paths: {\n * signIn: '/login',\n * signUp: '/register'\n * }\n * })\n * ```\n */\nexport function getInsforgeRoutes(config: GetInsforgeRoutesConfig): RouteObject[] {\n const { baseUrl, builtInAuth = true, paths = {} } = config;\n\n const {\n signIn = '/sign-in',\n signUp = '/sign-up',\n verifyEmail = '/verify-email',\n forgotPassword = '/forgot-password',\n resetPassword = '/reset-password',\n } = paths;\n\n const routes: RouteObject[] = [];\n\n // Only add redirect routes if using built-in auth\n if (builtInAuth) {\n routes.push(\n {\n path: signIn,\n element: <RedirectToAuth baseUrl={baseUrl} path=\"/auth/sign-in\" />,\n },\n {\n path: signUp,\n element: <RedirectToAuth baseUrl={baseUrl} path=\"/auth/sign-up\" />,\n },\n {\n path: verifyEmail,\n element: <RedirectToAuth baseUrl={baseUrl} path=\"/auth/verify-email\" />,\n },\n {\n path: forgotPassword,\n element: <RedirectToAuth baseUrl={baseUrl} path=\"/auth/forgot-password\" />,\n },\n {\n path: resetPassword,\n element: <RedirectToAuth baseUrl={baseUrl} path=\"/auth/reset-password\" />,\n }\n );\n }\n\n return routes;\n}\n"]}
|
package/dist/router.js
CHANGED
|
@@ -3,9 +3,9 @@ import { jsx } from 'react/jsx-runtime';
|
|
|
3
3
|
|
|
4
4
|
function RedirectToAuth({ baseUrl, path }) {
|
|
5
5
|
useEffect(() => {
|
|
6
|
-
const
|
|
6
|
+
const currentUrl = window.location.href;
|
|
7
7
|
const authUrl = new URL(path, baseUrl);
|
|
8
|
-
authUrl.searchParams.set("redirect",
|
|
8
|
+
authUrl.searchParams.set("redirect", currentUrl);
|
|
9
9
|
window.location.replace(authUrl.toString());
|
|
10
10
|
}, [baseUrl, path]);
|
|
11
11
|
return null;
|
package/dist/router.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/router/getInsforgeRoutes.tsx"],"names":[],"mappings":";;;AAyCA,SAAS,cAAA,CAAe,EAAE,OAAA,EAAS,IAAA,EAAK,EAAsC;AAC5E,EAAA,SAAA,CAAU,MAAM;
|
|
1
|
+
{"version":3,"sources":["../src/router/getInsforgeRoutes.tsx"],"names":[],"mappings":";;;AAyCA,SAAS,cAAA,CAAe,EAAE,OAAA,EAAS,IAAA,EAAK,EAAsC;AAC5E,EAAA,SAAA,CAAU,MAAM;AAEd,IAAA,MAAM,UAAA,GAAa,OAAO,QAAA,CAAS,IAAA;AACnC,IAAA,MAAM,OAAA,GAAU,IAAI,GAAA,CAAI,IAAA,EAAM,OAAO,CAAA;AACrC,IAAA,OAAA,CAAQ,YAAA,CAAa,GAAA,CAAI,UAAA,EAAY,UAAU,CAAA;AAC/C,IAAA,MAAA,CAAO,QAAA,CAAS,OAAA,CAAQ,OAAA,CAAQ,QAAA,EAAU,CAAA;AAAA,EAC5C,CAAA,EAAG,CAAC,OAAA,EAAS,IAAI,CAAC,CAAA;AAElB,EAAA,OAAO,IAAA;AACT;AA6CO,SAAS,kBAAkB,MAAA,EAAgD;AAChF,EAAA,MAAM,EAAE,OAAA,EAAS,WAAA,GAAc,MAAM,KAAA,GAAQ,IAAG,GAAI,MAAA;AAEpD,EAAA,MAAM;AAAA,IACJ,MAAA,GAAS,UAAA;AAAA,IACT,MAAA,GAAS,UAAA;AAAA,IACT,WAAA,GAAc,eAAA;AAAA,IACd,cAAA,GAAiB,kBAAA;AAAA,IACjB,aAAA,GAAgB;AAAA,GAClB,GAAI,KAAA;AAEJ,EAAA,MAAM,SAAwB,EAAC;AAG/B,EAAA,IAAI,WAAA,EAAa;AACf,IAAA,MAAA,CAAO,IAAA;AAAA,MACL;AAAA,QACE,IAAA,EAAM,MAAA;AAAA,QACN,OAAA,kBAAS,GAAA,CAAC,cAAA,EAAA,EAAe,OAAA,EAAkB,MAAK,eAAA,EAAgB;AAAA,OAClE;AAAA,MACA;AAAA,QACE,IAAA,EAAM,MAAA;AAAA,QACN,OAAA,kBAAS,GAAA,CAAC,cAAA,EAAA,EAAe,OAAA,EAAkB,MAAK,eAAA,EAAgB;AAAA,OAClE;AAAA,MACA;AAAA,QACE,IAAA,EAAM,WAAA;AAAA,QACN,OAAA,kBAAS,GAAA,CAAC,cAAA,EAAA,EAAe,OAAA,EAAkB,MAAK,oBAAA,EAAqB;AAAA,OACvE;AAAA,MACA;AAAA,QACE,IAAA,EAAM,cAAA;AAAA,QACN,OAAA,kBAAS,GAAA,CAAC,cAAA,EAAA,EAAe,OAAA,EAAkB,MAAK,uBAAA,EAAwB;AAAA,OAC1E;AAAA,MACA;AAAA,QACE,IAAA,EAAM,aAAA;AAAA,QACN,OAAA,kBAAS,GAAA,CAAC,cAAA,EAAA,EAAe,OAAA,EAAkB,MAAK,sBAAA,EAAuB;AAAA;AACzE,KACF;AAAA,EACF;AAEA,EAAA,OAAO,MAAA;AACT","file":"router.js","sourcesContent":["'use client';\n\nimport { useEffect } from 'react';\nimport type { RouteObject } from 'react-router-dom';\n\ninterface GetInsforgeRoutesConfig {\n /**\n * Base URL of your Insforge backend\n */\n baseUrl: string;\n\n /**\n * Whether to use built-in auth (deployed Insforge Auth)\n * When true: redirects to baseUrl/auth/* pages\n * When false: no redirect routes are added (use your own components)\n * @default true\n */\n builtInAuth?: boolean;\n\n /**\n * Custom paths for auth redirect routes\n * @default {\n * signIn: '/sign-in',\n * signUp: '/sign-up',\n * verifyEmail: '/verify-email',\n * forgotPassword: '/forgot-password',\n * resetPassword: '/reset-password'\n * }\n */\n paths?: {\n signIn?: string;\n signUp?: string;\n verifyEmail?: string;\n forgotPassword?: string;\n resetPassword?: string;\n };\n}\n\n/**\n * Helper component for redirecting to external auth\n */\nfunction RedirectToAuth({ baseUrl, path }: { baseUrl: string; path: string }) {\n useEffect(() => {\n // Redirect back to current URL - middleware/SDK will handle token from URL\n const currentUrl = window.location.href;\n const authUrl = new URL(path, baseUrl);\n authUrl.searchParams.set('redirect', currentUrl);\n window.location.replace(authUrl.toString());\n }, [baseUrl, path]);\n\n return null;\n}\n\n/**\n * Generates Insforge authentication redirect routes for React Router.\n *\n * Returns redirect routes for sign-in, sign-up, etc. that redirect to your deployed Insforge auth pages.\n *\n * @param config - Configuration for Insforge routes\n * @returns Array of RouteObject for React Router (redirect routes only)\n *\n * @example\n * ```tsx\n * import { createBrowserRouter } from 'react-router-dom';\n * import { getInsforgeRoutes } from '@insforge/react/router';\n *\n * const router = createBrowserRouter([\n * {\n * path: '/',\n * element: <Layout />,\n * children: [\n * { index: true, element: <Home /> },\n * { path: 'dashboard', element: <Dashboard /> }\n * ]\n * },\n * // Add redirect routes (sign-in, sign-up, etc.)\n * ...getInsforgeRoutes({\n * baseUrl: 'https://your-backend.com',\n * builtInAuth: true\n * })\n * ]);\n * ```\n *\n * @example\n * ```tsx\n * // Custom paths for redirect routes\n * ...getInsforgeRoutes({\n * baseUrl: 'https://your-backend.com',\n * builtInAuth: true,\n * paths: {\n * signIn: '/login',\n * signUp: '/register'\n * }\n * })\n * ```\n */\nexport function getInsforgeRoutes(config: GetInsforgeRoutesConfig): RouteObject[] {\n const { baseUrl, builtInAuth = true, paths = {} } = config;\n\n const {\n signIn = '/sign-in',\n signUp = '/sign-up',\n verifyEmail = '/verify-email',\n forgotPassword = '/forgot-password',\n resetPassword = '/reset-password',\n } = paths;\n\n const routes: RouteObject[] = [];\n\n // Only add redirect routes if using built-in auth\n if (builtInAuth) {\n routes.push(\n {\n path: signIn,\n element: <RedirectToAuth baseUrl={baseUrl} path=\"/auth/sign-in\" />,\n },\n {\n path: signUp,\n element: <RedirectToAuth baseUrl={baseUrl} path=\"/auth/sign-up\" />,\n },\n {\n path: verifyEmail,\n element: <RedirectToAuth baseUrl={baseUrl} path=\"/auth/verify-email\" />,\n },\n {\n path: forgotPassword,\n element: <RedirectToAuth baseUrl={baseUrl} path=\"/auth/forgot-password\" />,\n },\n {\n path: resetPassword,\n element: <RedirectToAuth baseUrl={baseUrl} path=\"/auth/reset-password\" />,\n }\n );\n }\n\n return routes;\n}\n"]}
|
package/package.json
CHANGED