@contentgrowth/content-auth 0.6.3 → 0.6.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.
@@ -11,7 +11,7 @@ import {
11
11
  schema_exports,
12
12
  verifyPassword,
13
13
  verifyTurnstile
14
- } from "../chunk-V434IQQD.js";
14
+ } from "../chunk-KUS3REJX.js";
15
15
  import "../chunk-R5U7XKVJ.js";
16
16
  export {
17
17
  Hono,
@@ -637,6 +637,44 @@ var createAuth = (config) => {
637
637
  console.log("[ContentAuth-DEBUG] Other options passed to betterAuth():", Object.keys(otherOptions).join(", "));
638
638
  console.log("[ContentAuth-DEBUG] ========================================");
639
639
  }
640
+ auth.createUser = async (options) => {
641
+ const { email, password, name, emailVerified = false } = options;
642
+ const signupRequest = new Request(`${baseUrl}/api/auth/sign-up/email`, {
643
+ method: "POST",
644
+ headers: { "Content-Type": "application/json" },
645
+ body: JSON.stringify({
646
+ email: email.toLowerCase().trim(),
647
+ password,
648
+ name: name || email.split("@")[0],
649
+ callbackURL: "/"
650
+ })
651
+ });
652
+ const signupResponse = await auth.handler(signupRequest);
653
+ if (!signupResponse.ok) {
654
+ const errorData = await signupResponse.json();
655
+ throw new Error(`Failed to create user: ${JSON.stringify(errorData)}`);
656
+ }
657
+ const signupData = await signupResponse.json();
658
+ if (emailVerified && signupData.user?.id && rawDb?.prepare) {
659
+ await rawDb.prepare(
660
+ `UPDATE ${userTableName} SET ${userIdColumn === "id" ? "emailVerified" : schemaMapping?.user?.fields?.emailVerified || "emailVerified"} = 1 WHERE ${userIdColumn} = ?`
661
+ ).bind(signupData.user.id).run();
662
+ }
663
+ return signupData.user;
664
+ };
665
+ auth.resetUserPassword = async (userId, newPassword) => {
666
+ if (!rawDb?.prepare) {
667
+ throw new Error("Password reset requires database access");
668
+ }
669
+ const hashedPassword = await hashPassword(newPassword);
670
+ const accountIdField = schemaMapping?.account?.fields?.userId || "userId";
671
+ const passwordField = schemaMapping?.account?.fields?.password || "password";
672
+ const updatedAtField = schemaMapping?.account?.fields?.updatedAt || "updatedAt";
673
+ await rawDb.prepare(
674
+ `UPDATE ${accountTableName} SET ${passwordField} = ?, ${updatedAtField} = ? WHERE ${accountIdField} = ? AND providerId = 'credential'`
675
+ ).bind(hashedPassword, Date.now(), userId).run();
676
+ return { success: true };
677
+ };
640
678
  return auth;
641
679
  };
642
680
  var authMiddleware = (auth) => {
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  schema_exports,
12
12
  verifyPassword,
13
13
  verifyTurnstile
14
- } from "./chunk-V434IQQD.js";
14
+ } from "./chunk-KUS3REJX.js";
15
15
  import {
16
16
  AuthForm,
17
17
  CreateOrganizationForm,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentgrowth/content-auth",
3
- "version": "0.6.3",
3
+ "version": "0.6.4",
4
4
  "description": "Better Auth wrapper with UI components for Cloudflare Workers & Pages. Includes custom schema mapping, Turnstile bot protection, and email normalization.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",