@contentgrowth/content-auth 0.3.2 → 0.3.4

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.
@@ -9,7 +9,7 @@ import {
9
9
  normalizeEmail,
10
10
  schema_exports,
11
11
  verifyTurnstile
12
- } from "../chunk-HTFOOF6M.js";
12
+ } from "../chunk-SF5CUX53.js";
13
13
  import "../chunk-R5U7XKVJ.js";
14
14
  export {
15
15
  Hono,
@@ -83,7 +83,27 @@ var AuthForm = ({
83
83
  }
84
84
  onSuccess?.(response.data);
85
85
  } catch (err) {
86
- setError(err.message || "An error occurred");
86
+ const errorMessage = err.message || "";
87
+ const errorCode = err.code || "";
88
+ let friendlyMessage = "An error occurred. Please try again.";
89
+ if (errorMessage.includes("TURNSTILE") || errorMessage.includes("security challenge")) {
90
+ friendlyMessage = "Security verification failed. Please complete the challenge and try again.";
91
+ } else if (errorMessage.includes("EMAIL_EXISTS") || errorMessage.includes("already exists")) {
92
+ friendlyMessage = "An account with this email already exists. Try signing in instead.";
93
+ } else if (errorMessage.includes("Invalid email") || errorMessage.includes("invalid email")) {
94
+ friendlyMessage = "Please enter a valid email address.";
95
+ } else if (errorMessage.includes("Invalid password") || errorMessage.includes("incorrect")) {
96
+ friendlyMessage = "Invalid email or password. Please check your credentials.";
97
+ } else if (errorMessage.includes("User not found")) {
98
+ friendlyMessage = "No account found with this email. Try signing up instead.";
99
+ } else if (errorMessage.includes("too short") || errorMessage.includes("password")) {
100
+ friendlyMessage = "Password must be at least 8 characters long.";
101
+ } else if (errorCode === "BAD_REQUEST" || err.status === 400) {
102
+ friendlyMessage = "Please check your information and try again.";
103
+ } else if (err.message) {
104
+ friendlyMessage = err.message;
105
+ }
106
+ setError(friendlyMessage);
87
107
  if (turnstileRef.current) {
88
108
  turnstileRef.current.reset();
89
109
  setTurnstileToken(null);
@@ -33,11 +33,21 @@ async function verifyTurnstile(secretKey, token, remoteIp) {
33
33
  },
34
34
  body: formData.toString()
35
35
  });
36
+ let result;
37
+ try {
38
+ result = await response.json();
39
+ } catch (e) {
40
+ console.error(`[Turnstile] Failed to parse response: ${response.status}`);
41
+ return { success: false, error: "Security verification failed. Please try again." };
42
+ }
36
43
  if (!response.ok) {
37
- console.error(`[Turnstile] Siteverify API error: ${response.status}`);
38
- return { success: false, error: `API error: ${response.status}` };
44
+ const errorCodes = result["error-codes"] || [];
45
+ console.error(`[Turnstile] Siteverify API error ${response.status}: ${errorCodes.join(", ")}`);
46
+ if (errorCodes.length > 0) {
47
+ return { success: false, error: mapTurnstileError(errorCodes) };
48
+ }
49
+ return { success: false, error: "Security verification failed. Please try again." };
39
50
  }
40
- const result = await response.json();
41
51
  if (result.success) {
42
52
  return { success: true, hostname: result.hostname };
43
53
  } else {
@@ -7,7 +7,7 @@ import {
7
7
  PasswordChanger,
8
8
  ProfileEditor,
9
9
  ResetPasswordForm
10
- } from "../chunk-6MYNRK2N.js";
10
+ } from "../chunk-CTASTCWI.js";
11
11
  import {
12
12
  authClient,
13
13
  createClient
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  normalizeEmail,
10
10
  schema_exports,
11
11
  verifyTurnstile
12
- } from "./chunk-HTFOOF6M.js";
12
+ } from "./chunk-SF5CUX53.js";
13
13
  import {
14
14
  AuthForm,
15
15
  CreateOrganizationForm,
@@ -19,7 +19,7 @@ import {
19
19
  PasswordChanger,
20
20
  ProfileEditor,
21
21
  ResetPasswordForm
22
- } from "./chunk-6MYNRK2N.js";
22
+ } from "./chunk-CTASTCWI.js";
23
23
  import {
24
24
  authClient,
25
25
  createClient
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentgrowth/content-auth",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "description": "Better Auth wrapper with UI components for Cloudflare Workers & Pages. Includes Turnstile bot protection and email normalization.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",