@convex-dev/better-auth 0.11.5 → 0.12.0

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.
Files changed (88) hide show
  1. package/dist/auth-options.d.ts.map +1 -1
  2. package/dist/auth-options.js +1 -0
  3. package/dist/auth-options.js.map +1 -1
  4. package/dist/client/adapter-utils.d.ts +8 -2
  5. package/dist/client/adapter-utils.d.ts.map +1 -1
  6. package/dist/client/adapter-utils.js +8 -3
  7. package/dist/client/adapter-utils.js.map +1 -1
  8. package/dist/client/adapter.d.ts.map +1 -1
  9. package/dist/client/adapter.js +5 -0
  10. package/dist/client/adapter.js.map +1 -1
  11. package/dist/client/create-api.d.ts +6 -0
  12. package/dist/client/create-api.d.ts.map +1 -1
  13. package/dist/client/create-api.js +1 -0
  14. package/dist/client/create-api.js.map +1 -1
  15. package/dist/client/create-schema.d.ts.map +1 -1
  16. package/dist/client/create-schema.js +38 -8
  17. package/dist/client/create-schema.js.map +1 -1
  18. package/dist/component/_generated/component.d.ts +543 -28
  19. package/dist/component/_generated/component.d.ts.map +1 -1
  20. package/dist/component/adapter.d.ts +6 -0
  21. package/dist/component/adapter.d.ts.map +1 -1
  22. package/dist/component/schema.d.ts +9 -4
  23. package/dist/component/schema.d.ts.map +1 -1
  24. package/dist/component/schema.js +4 -2
  25. package/dist/component/schema.js.map +1 -1
  26. package/dist/component/testProfiles/adapterAdditionalFields.d.ts +6 -0
  27. package/dist/component/testProfiles/adapterAdditionalFields.d.ts.map +1 -1
  28. package/dist/component/testProfiles/adapterOrganizationJoins.d.ts +6 -0
  29. package/dist/component/testProfiles/adapterOrganizationJoins.d.ts.map +1 -1
  30. package/dist/component/testProfiles/adapterPluginTable.d.ts +6 -0
  31. package/dist/component/testProfiles/adapterPluginTable.d.ts.map +1 -1
  32. package/dist/component/testProfiles/adapterRenameField.d.ts +6 -0
  33. package/dist/component/testProfiles/adapterRenameField.d.ts.map +1 -1
  34. package/dist/component/testProfiles/adapterRenameUserCustom.d.ts +6 -0
  35. package/dist/component/testProfiles/adapterRenameUserCustom.d.ts.map +1 -1
  36. package/dist/component/testProfiles/adapterRenameUserTable.d.ts +6 -0
  37. package/dist/component/testProfiles/adapterRenameUserTable.d.ts.map +1 -1
  38. package/dist/component/testProfiles/schema.profile-additional-fields.d.ts +3 -1
  39. package/dist/component/testProfiles/schema.profile-additional-fields.d.ts.map +1 -1
  40. package/dist/component/testProfiles/schema.profile-plugin-table.d.ts +3 -1
  41. package/dist/component/testProfiles/schema.profile-plugin-table.d.ts.map +1 -1
  42. package/dist/plugins/convex/client.d.ts +1 -0
  43. package/dist/plugins/convex/client.d.ts.map +1 -1
  44. package/dist/plugins/convex/client.js +2 -0
  45. package/dist/plugins/convex/client.js.map +1 -1
  46. package/dist/plugins/convex/index.d.ts +2 -1
  47. package/dist/plugins/convex/index.d.ts.map +1 -1
  48. package/dist/plugins/convex/index.js +15 -2
  49. package/dist/plugins/convex/index.js.map +1 -1
  50. package/dist/plugins/cross-domain/client.d.ts +1 -12
  51. package/dist/plugins/cross-domain/client.d.ts.map +1 -1
  52. package/dist/plugins/cross-domain/client.js +14 -26
  53. package/dist/plugins/cross-domain/client.js.map +1 -1
  54. package/dist/plugins/cross-domain/index.d.ts +1 -0
  55. package/dist/plugins/cross-domain/index.d.ts.map +1 -1
  56. package/dist/plugins/cross-domain/index.js +15 -4
  57. package/dist/plugins/cross-domain/index.js.map +1 -1
  58. package/dist/test/adapter-factory/basic.d.ts +4 -0
  59. package/dist/test/adapter-factory/basic.d.ts.map +1 -1
  60. package/dist/test/adapter-factory/convex-custom.d.ts +1 -1
  61. package/dist/test/adapter-factory/convex-custom.d.ts.map +1 -1
  62. package/dist/test/adapter-factory/convex-custom.js +20 -0
  63. package/dist/test/adapter-factory/convex-custom.js.map +1 -1
  64. package/dist/utils/index.d.ts +1 -0
  65. package/dist/utils/index.d.ts.map +1 -1
  66. package/dist/utils/index.js +5 -1
  67. package/dist/utils/index.js.map +1 -1
  68. package/dist/version.d.ts +2 -0
  69. package/dist/version.d.ts.map +1 -0
  70. package/dist/version.js +2 -0
  71. package/dist/version.js.map +1 -0
  72. package/package.json +6 -5
  73. package/src/auth-options.ts +1 -0
  74. package/src/client/adapter-utils.ts +13 -5
  75. package/src/client/adapter.ts +7 -0
  76. package/src/client/create-api.ts +3 -0
  77. package/src/client/create-schema.ts +46 -8
  78. package/src/component/_generated/component.ts +718 -35
  79. package/src/component/schema.ts +5 -3
  80. package/src/plugins/convex/client.ts +2 -0
  81. package/src/plugins/convex/index.ts +16 -3
  82. package/src/plugins/cross-domain/client.test.ts +41 -30
  83. package/src/plugins/cross-domain/client.ts +17 -44
  84. package/src/plugins/cross-domain/index.test.ts +129 -51
  85. package/src/plugins/cross-domain/index.ts +20 -7
  86. package/src/test/adapter-factory/convex-custom.ts +23 -0
  87. package/src/utils/index.ts +6 -1
  88. package/src/version.ts +1 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC"}
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "bugs": {
7
7
  "url": "https://github.com/get-convex/better-auth/issues"
8
8
  },
9
- "version": "0.11.5",
9
+ "version": "0.12.0",
10
10
  "license": "Apache-2.0",
11
11
  "keywords": [
12
12
  "convex",
@@ -30,6 +30,7 @@
30
30
  "test:e2e": "npm run build && cd e2e && npm run test",
31
31
  "test:coverage": "vitest run --coverage --coverage.reporter=text",
32
32
  "preversion": "npm ci && npm run build:clean && npm run test && npm run lint && npm run typecheck",
33
+ "prepublishOnly": "node scripts/sync-version.mjs",
33
34
  "alpha": "npm version prerelease --preid alpha && npm publish --tag alpha && git push --follow-tags",
34
35
  "release": "npm version patch && npm publish && git push --follow-tags",
35
36
  "version": "(npm whoami || npm login) && vim -c 'normal o' -c 'normal o## '$npm_package_version CHANGELOG.md && prettier -w CHANGELOG.md && git add CHANGELOG.md"
@@ -101,13 +102,13 @@
101
102
  }
102
103
  },
103
104
  "peerDependencies": {
104
- "better-auth": ">=1.5.0 <1.6.0",
105
+ "better-auth": ">=1.6.9 <1.7.0",
105
106
  "convex": "^1.25.0",
106
107
  "react": "^18.3.1 || ^19.0.0"
107
108
  },
108
109
  "devDependencies": {
109
- "@better-auth/core": "~1.5.6",
110
- "@better-auth/test-utils": "~1.5.6",
110
+ "@better-auth/core": "~1.6.9",
111
+ "@better-auth/test-utils": "~1.6.9",
111
112
  "@edge-runtime/vm": "5.0.0",
112
113
  "@eslint/eslintrc": "3.3.1",
113
114
  "@eslint/js": "9.39.1",
@@ -117,7 +118,7 @@
117
118
  "@types/react": "19.2.14",
118
119
  "@types/react-dom": "19.2.3",
119
120
  "@types/semver": "^7.7.0",
120
- "better-auth": "~1.5.6",
121
+ "better-auth": "~1.6.9",
121
122
  "chokidar-cli": "3.0.0",
122
123
  "concurrently": "^9.2.0",
123
124
  "convex": "1.35.1",
@@ -37,6 +37,7 @@ export const options = {
37
37
  }),
38
38
  oidcProvider({
39
39
  loginPage: "/login",
40
+ __skipDeprecationWarning: true,
40
41
  }),
41
42
  bearer(),
42
43
  oneTimeToken(),
@@ -41,6 +41,7 @@ export const adapterWhereValidator = v.object({
41
41
  v.null()
42
42
  ),
43
43
  connector: v.optional(v.union(v.literal("AND"), v.literal("OR"))),
44
+ mode: v.optional(v.union(v.literal("sensitive"), v.literal("insensitive"))),
44
45
  });
45
46
 
46
47
  export const adapterArgsValidator = v.object({
@@ -106,6 +107,7 @@ const findIndex = (
106
107
  | "ends_with";
107
108
  value: string | number | boolean | null | string[] | number[];
108
109
  connector?: "AND" | "OR";
110
+ mode?: "sensitive" | "insensitive";
109
111
  }[];
110
112
  sortBy?: {
111
113
  field: string;
@@ -185,11 +187,7 @@ const findIndex = (
185
187
  // We internally use _creationTime in place of Better Auth's createdAt
186
188
  const indexFields = indexEqFields
187
189
  .map(([field]) => field)
188
- .concat(
189
- boundField && boundField !== "createdAt"
190
- ? boundField
191
- : ""
192
- )
190
+ .concat(boundField && boundField !== "createdAt" ? boundField : "")
193
191
  .concat(
194
192
  sortField && sortField !== "createdAt" && boundField !== sortField
195
193
  ? sortField
@@ -499,6 +497,11 @@ export const paginate = async <
499
497
  `_id can only be used with eq, in, or not_in operator: ${JSON.stringify(args.where)}`
500
498
  );
501
499
  }
500
+ if (args.where?.some((w) => w.mode === "insensitive")) {
501
+ throw new Error(
502
+ `Case-insensitive queries (mode: "insensitive") are not supported by the Convex adapter. Store values in a normalized form (e.g. lowercase on write) and query against the normalized value.`
503
+ );
504
+ }
502
505
  // If any where clause is "eq" (or missing operator) on a unique field,
503
506
  // we can only return a single document, so we get it and use any other
504
507
  // where clauses as static filters.
@@ -514,6 +517,11 @@ export const paginate = async <
514
517
  model: args.model,
515
518
  where: [uniqueWhere],
516
519
  }) || {};
520
+ if (uniqueWhere.field !== "_id" && !index) {
521
+ throw new Error(
522
+ `No index found for ${args.model}.${uniqueWhere.field}`
523
+ );
524
+ }
517
525
  const doc =
518
526
  uniqueWhere.field === "_id"
519
527
  ? await ctx.db.get(uniqueWhere.value as GenericId<T>)
@@ -93,6 +93,13 @@ const parseWhere = (
93
93
  return [];
94
94
  }
95
95
  const whereArray = Array.isArray(where) ? where : [where];
96
+ for (const w of whereArray) {
97
+ if (w.mode === "insensitive") {
98
+ throw new Error(
99
+ `Case-insensitive queries (mode: "insensitive") are not supported by the Convex adapter. Store values in a normalized form (e.g. lowercase on write) and query against the normalized value. Field: ${w.field}`
100
+ );
101
+ }
102
+ }
96
103
  return whereArray.map((w) => {
97
104
  if (w.value instanceof Date) {
98
105
  return {
@@ -55,6 +55,9 @@ const whereValidator = (
55
55
  v.null()
56
56
  ),
57
57
  connector: v.optional(v.union(v.literal("AND"), v.literal("OR"))),
58
+ mode: v.optional(
59
+ v.union(v.literal("sensitive"), v.literal("insensitive"))
60
+ ),
58
61
  });
59
62
 
60
63
  export const createApi = <Schema extends SchemaDefinition<any, any>>(
@@ -1,5 +1,18 @@
1
1
  import type { BetterAuthDBSchema, DBFieldAttribute } from "better-auth/db";
2
2
 
3
+ const resolveCdTarget = (
4
+ relativeDir: string | null,
5
+ cwdBasename: string
6
+ ): string | null => {
7
+ if (relativeDir === "") {
8
+ return null;
9
+ }
10
+ if (relativeDir !== null) {
11
+ return relativeDir;
12
+ }
13
+ return cwdBasename;
14
+ };
15
+
3
16
  // Manually add fields to index on for schema generation,
4
17
  // all fields in the schema specialFields are automatically indexed
5
18
  export const indexFields = {
@@ -66,11 +79,12 @@ export const createSchema = async ({
66
79
  tables: BetterAuthDBSchema;
67
80
  file?: string;
68
81
  }) => {
69
- // stop convex esbuild from throwing over this import, only runs
70
- // in the better auth cli
71
- const pathImport = "path";
72
- const path = await import(pathImport);
73
- const baseName = path.basename(path.resolve(process.cwd(), file ?? ""));
82
+ // Hide these node builtins from Convex's esbuild so it doesn't try to
83
+ // resolve them at bundle time. Only runs from the better-auth CLI.
84
+ const path = await import(["p", "a", "t", "h"].join(""));
85
+ const fs = await import(["f", "s"].join(""));
86
+ const cwd = process.cwd();
87
+ const baseName = path.basename(path.resolve(cwd, file ?? ""));
74
88
  // if the target directory is named "convex", they're almost definitely
75
89
  // generating the schema in the wrong directory, likely would replace the
76
90
  // app schema
@@ -79,11 +93,35 @@ export const createSchema = async ({
79
93
  "Better Auth schema must be generated in the Better Auth component directory."
80
94
  );
81
95
  }
96
+
97
+ const findProjectRoot = (dir: string): string | null => {
98
+ if (fs.existsSync(path.join(dir, "package.json"))) {
99
+ return dir;
100
+ }
101
+ const parent = path.dirname(dir);
102
+ if (parent === dir) {
103
+ return null;
104
+ }
105
+ return findProjectRoot(parent);
106
+ };
107
+
108
+ const projectRoot = findProjectRoot(cwd);
109
+ const relativeDir =
110
+ projectRoot !== null
111
+ ? path.relative(projectRoot, cwd).split(path.sep).join("/")
112
+ : null;
113
+ const generateCommand = `npx auth generate${file ? ` --output ${file}` : ""}`;
114
+ const cdTarget = resolveCdTarget(relativeDir, path.basename(cwd));
115
+ const commandBlock = cdTarget
116
+ ? ` * cd ${cdTarget}\n * ${generateCommand}`
117
+ : ` * ${generateCommand}`;
118
+
82
119
  let code: string = `/**
83
120
  * This file is auto-generated. Do not edit this file manually.
84
- * To regenerate the schema, run:
85
- * \`npx @better-auth/cli generate --output ${file} -y\`
86
- *
121
+ * To regenerate the schema, from your project root:
122
+ *
123
+ ${commandBlock}
124
+ *
87
125
  * To customize the schema, generate to an alternate file and import
88
126
  * the table definitions to your schema file. See
89
127
  * https://labs.convex.dev/better-auth/features/local-install#adding-custom-indexes.