@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.
- package/dist/auth-options.d.ts.map +1 -1
- package/dist/auth-options.js +1 -0
- package/dist/auth-options.js.map +1 -1
- package/dist/client/adapter-utils.d.ts +8 -2
- package/dist/client/adapter-utils.d.ts.map +1 -1
- package/dist/client/adapter-utils.js +8 -3
- package/dist/client/adapter-utils.js.map +1 -1
- package/dist/client/adapter.d.ts.map +1 -1
- package/dist/client/adapter.js +5 -0
- package/dist/client/adapter.js.map +1 -1
- package/dist/client/create-api.d.ts +6 -0
- package/dist/client/create-api.d.ts.map +1 -1
- package/dist/client/create-api.js +1 -0
- package/dist/client/create-api.js.map +1 -1
- package/dist/client/create-schema.d.ts.map +1 -1
- package/dist/client/create-schema.js +38 -8
- package/dist/client/create-schema.js.map +1 -1
- package/dist/component/_generated/component.d.ts +543 -28
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/adapter.d.ts +6 -0
- package/dist/component/adapter.d.ts.map +1 -1
- package/dist/component/schema.d.ts +9 -4
- package/dist/component/schema.d.ts.map +1 -1
- package/dist/component/schema.js +4 -2
- package/dist/component/schema.js.map +1 -1
- package/dist/component/testProfiles/adapterAdditionalFields.d.ts +6 -0
- package/dist/component/testProfiles/adapterAdditionalFields.d.ts.map +1 -1
- package/dist/component/testProfiles/adapterOrganizationJoins.d.ts +6 -0
- package/dist/component/testProfiles/adapterOrganizationJoins.d.ts.map +1 -1
- package/dist/component/testProfiles/adapterPluginTable.d.ts +6 -0
- package/dist/component/testProfiles/adapterPluginTable.d.ts.map +1 -1
- package/dist/component/testProfiles/adapterRenameField.d.ts +6 -0
- package/dist/component/testProfiles/adapterRenameField.d.ts.map +1 -1
- package/dist/component/testProfiles/adapterRenameUserCustom.d.ts +6 -0
- package/dist/component/testProfiles/adapterRenameUserCustom.d.ts.map +1 -1
- package/dist/component/testProfiles/adapterRenameUserTable.d.ts +6 -0
- package/dist/component/testProfiles/adapterRenameUserTable.d.ts.map +1 -1
- package/dist/component/testProfiles/schema.profile-additional-fields.d.ts +3 -1
- package/dist/component/testProfiles/schema.profile-additional-fields.d.ts.map +1 -1
- package/dist/component/testProfiles/schema.profile-plugin-table.d.ts +3 -1
- package/dist/component/testProfiles/schema.profile-plugin-table.d.ts.map +1 -1
- package/dist/plugins/convex/client.d.ts +1 -0
- package/dist/plugins/convex/client.d.ts.map +1 -1
- package/dist/plugins/convex/client.js +2 -0
- package/dist/plugins/convex/client.js.map +1 -1
- package/dist/plugins/convex/index.d.ts +2 -1
- package/dist/plugins/convex/index.d.ts.map +1 -1
- package/dist/plugins/convex/index.js +15 -2
- package/dist/plugins/convex/index.js.map +1 -1
- package/dist/plugins/cross-domain/client.d.ts +1 -12
- package/dist/plugins/cross-domain/client.d.ts.map +1 -1
- package/dist/plugins/cross-domain/client.js +14 -26
- package/dist/plugins/cross-domain/client.js.map +1 -1
- package/dist/plugins/cross-domain/index.d.ts +1 -0
- package/dist/plugins/cross-domain/index.d.ts.map +1 -1
- package/dist/plugins/cross-domain/index.js +15 -4
- package/dist/plugins/cross-domain/index.js.map +1 -1
- package/dist/test/adapter-factory/basic.d.ts +4 -0
- package/dist/test/adapter-factory/basic.d.ts.map +1 -1
- package/dist/test/adapter-factory/convex-custom.d.ts +1 -1
- package/dist/test/adapter-factory/convex-custom.d.ts.map +1 -1
- package/dist/test/adapter-factory/convex-custom.js +20 -0
- package/dist/test/adapter-factory/convex-custom.js.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +5 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +2 -0
- package/dist/version.js.map +1 -0
- package/package.json +6 -5
- package/src/auth-options.ts +1 -0
- package/src/client/adapter-utils.ts +13 -5
- package/src/client/adapter.ts +7 -0
- package/src/client/create-api.ts +3 -0
- package/src/client/create-schema.ts +46 -8
- package/src/component/_generated/component.ts +718 -35
- package/src/component/schema.ts +5 -3
- package/src/plugins/convex/client.ts +2 -0
- package/src/plugins/convex/index.ts +16 -3
- package/src/plugins/cross-domain/client.test.ts +41 -30
- package/src/plugins/cross-domain/client.ts +17 -44
- package/src/plugins/cross-domain/index.test.ts +129 -51
- package/src/plugins/cross-domain/index.ts +20 -7
- package/src/test/adapter-factory/convex-custom.ts +23 -0
- package/src/utils/index.ts +6 -1
- 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.
|
|
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.
|
|
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.
|
|
110
|
-
"@better-auth/test-utils": "~1.
|
|
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.
|
|
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",
|
package/src/auth-options.ts
CHANGED
|
@@ -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>)
|
package/src/client/adapter.ts
CHANGED
|
@@ -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 {
|
package/src/client/create-api.ts
CHANGED
|
@@ -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
|
-
//
|
|
70
|
-
//
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
const
|
|
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,
|
|
85
|
-
*
|
|
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.
|