@convex-dev/better-auth 0.10.13 → 0.11.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 +0 -2
- package/dist/auth-options.js.map +1 -1
- package/dist/client/adapter-utils.d.ts +10 -10
- package/dist/client/adapter-utils.d.ts.map +1 -1
- package/dist/client/adapter-utils.js +41 -32
- package/dist/client/adapter-utils.js.map +1 -1
- package/dist/client/adapter.d.ts +1 -1
- package/dist/client/adapter.d.ts.map +1 -1
- package/dist/client/adapter.js +113 -7
- package/dist/client/adapter.js.map +1 -1
- package/dist/client/create-api.d.ts +8 -7
- 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-client.d.ts +1 -1
- package/dist/client/create-client.d.ts.map +1 -1
- package/dist/client/create-client.js +8 -7
- package/dist/client/create-client.js.map +1 -1
- package/dist/client/create-schema.d.ts +0 -1
- package/dist/client/create-schema.d.ts.map +1 -1
- package/dist/client/create-schema.js +0 -1
- package/dist/client/create-schema.js.map +1 -1
- package/dist/component/_generated/api.d.ts +12 -0
- package/dist/component/_generated/api.d.ts.map +1 -1
- package/dist/component/_generated/api.js.map +1 -1
- package/dist/component/_generated/component.d.ts +7407 -92
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/adapter.d.ts +8 -7
- package/dist/component/adapter.d.ts.map +1 -1
- package/dist/component/adapterTest.d.ts +1 -7
- package/dist/component/adapterTest.d.ts.map +1 -1
- package/dist/component/adapterTest.js +193 -390
- package/dist/component/adapterTest.js.map +1 -1
- package/dist/component/schema.d.ts +35 -74
- package/dist/component/schema.d.ts.map +1 -1
- package/dist/component/schema.js +16 -21
- package/dist/component/schema.js.map +1 -1
- package/dist/component/testProfiles/adapterAdditionalFields.d.ts +131 -0
- package/dist/component/testProfiles/adapterAdditionalFields.d.ts.map +1 -0
- package/dist/component/testProfiles/adapterAdditionalFields.js +5 -0
- package/dist/component/testProfiles/adapterAdditionalFields.js.map +1 -0
- package/dist/component/testProfiles/adapterOrganizationJoins.d.ts +131 -0
- package/dist/component/testProfiles/adapterOrganizationJoins.d.ts.map +1 -0
- package/dist/component/testProfiles/adapterOrganizationJoins.js +5 -0
- package/dist/component/testProfiles/adapterOrganizationJoins.js.map +1 -0
- package/dist/component/testProfiles/adapterPluginTable.d.ts +131 -0
- package/dist/component/testProfiles/adapterPluginTable.d.ts.map +1 -0
- package/dist/component/testProfiles/adapterPluginTable.js +5 -0
- package/dist/component/testProfiles/adapterPluginTable.js.map +1 -0
- package/dist/component/testProfiles/adapterRenameField.d.ts +131 -0
- package/dist/component/testProfiles/adapterRenameField.d.ts.map +1 -0
- package/dist/component/testProfiles/adapterRenameField.js +5 -0
- package/dist/component/testProfiles/adapterRenameField.js.map +1 -0
- package/dist/component/testProfiles/adapterRenameUserCustom.d.ts +131 -0
- package/dist/component/testProfiles/adapterRenameUserCustom.d.ts.map +1 -0
- package/dist/component/testProfiles/adapterRenameUserCustom.js +5 -0
- package/dist/component/testProfiles/adapterRenameUserCustom.js.map +1 -0
- package/dist/component/testProfiles/adapterRenameUserTable.d.ts +131 -0
- package/dist/component/testProfiles/adapterRenameUserTable.d.ts.map +1 -0
- package/dist/component/testProfiles/adapterRenameUserTable.js +5 -0
- package/dist/component/testProfiles/adapterRenameUserTable.js.map +1 -0
- package/dist/component/testProfiles/auth-options.profile-additional-fields.d.ts +3 -0
- package/dist/component/testProfiles/auth-options.profile-additional-fields.d.ts.map +1 -0
- package/dist/component/testProfiles/auth-options.profile-additional-fields.js +38 -0
- package/dist/component/testProfiles/auth-options.profile-additional-fields.js.map +1 -0
- package/dist/component/testProfiles/auth-options.profile-plugin-table.d.ts +3 -0
- package/dist/component/testProfiles/auth-options.profile-plugin-table.d.ts.map +1 -0
- package/dist/component/testProfiles/auth-options.profile-plugin-table.js +92 -0
- package/dist/component/testProfiles/auth-options.profile-plugin-table.js.map +1 -0
- package/dist/component/testProfiles/auth-options.profile-rename-joins.d.ts +6 -0
- package/dist/component/testProfiles/auth-options.profile-rename-joins.d.ts.map +1 -0
- package/dist/component/testProfiles/auth-options.profile-rename-joins.js +49 -0
- package/dist/component/testProfiles/auth-options.profile-rename-joins.js.map +1 -0
- package/dist/component/testProfiles/schema.profile-additional-fields.d.ts +227 -0
- package/dist/component/testProfiles/schema.profile-additional-fields.d.ts.map +1 -0
- package/dist/component/testProfiles/schema.profile-additional-fields.js +37 -0
- package/dist/component/testProfiles/schema.profile-additional-fields.js.map +1 -0
- package/dist/component/testProfiles/schema.profile-plugin-table.d.ts +450 -0
- package/dist/component/testProfiles/schema.profile-plugin-table.d.ts.map +1 -0
- package/dist/component/testProfiles/schema.profile-plugin-table.js +116 -0
- package/dist/component/testProfiles/schema.profile-plugin-table.js.map +1 -0
- package/dist/nextjs/index.d.ts.map +1 -1
- package/dist/nextjs/index.js +1 -0
- package/dist/nextjs/index.js.map +1 -1
- package/dist/plugins/convex/index.d.ts +131 -12
- package/dist/plugins/convex/index.d.ts.map +1 -1
- package/dist/plugins/convex/index.js +12 -5
- package/dist/plugins/convex/index.js.map +1 -1
- package/dist/plugins/cross-domain/client.d.ts +1 -1
- package/dist/plugins/cross-domain/index.d.ts +126 -1
- package/dist/plugins/cross-domain/index.d.ts.map +1 -1
- package/dist/plugins/cross-domain/index.js +10 -15
- package/dist/plugins/cross-domain/index.js.map +1 -1
- package/dist/react-start/index.d.ts.map +1 -1
- package/dist/react-start/index.js +1 -0
- package/dist/react-start/index.js.map +1 -1
- package/dist/test/adapter-factory/auth-flow.d.ts +42 -0
- package/dist/test/adapter-factory/auth-flow.d.ts.map +1 -0
- package/dist/test/adapter-factory/auth-flow.js +145 -0
- package/dist/test/adapter-factory/auth-flow.js.map +1 -0
- package/dist/test/adapter-factory/basic.d.ts +190 -0
- package/dist/test/adapter-factory/basic.d.ts.map +1 -0
- package/dist/test/adapter-factory/basic.js +2713 -0
- package/dist/test/adapter-factory/basic.js.map +1 -0
- package/dist/test/adapter-factory/convex-custom.d.ts +18 -0
- package/dist/test/adapter-factory/convex-custom.d.ts.map +1 -0
- package/dist/test/adapter-factory/convex-custom.js +610 -0
- package/dist/test/adapter-factory/convex-custom.js.map +1 -0
- package/dist/test/adapter-factory/index.d.ts +11 -0
- package/dist/test/adapter-factory/index.d.ts.map +1 -0
- package/dist/test/adapter-factory/index.js +11 -0
- package/dist/test/adapter-factory/index.js.map +1 -0
- package/dist/test/adapter-factory/joins.d.ts +18 -0
- package/dist/test/adapter-factory/joins.d.ts.map +1 -0
- package/dist/test/adapter-factory/joins.js +22 -0
- package/dist/test/adapter-factory/joins.js.map +1 -0
- package/dist/test/adapter-factory/number-id.d.ts +18 -0
- package/dist/test/adapter-factory/number-id.d.ts.map +1 -0
- package/dist/test/adapter-factory/number-id.js +36 -0
- package/dist/test/adapter-factory/number-id.js.map +1 -0
- package/dist/test/adapter-factory/profile-additional-fields.d.ts +71 -0
- package/dist/test/adapter-factory/profile-additional-fields.d.ts.map +1 -0
- package/dist/test/adapter-factory/profile-additional-fields.js +44 -0
- package/dist/test/adapter-factory/profile-additional-fields.js.map +1 -0
- package/dist/test/adapter-factory/profile-plugin-table.d.ts +19 -0
- package/dist/test/adapter-factory/profile-plugin-table.d.ts.map +1 -0
- package/dist/test/adapter-factory/profile-plugin-table.js +25 -0
- package/dist/test/adapter-factory/profile-plugin-table.js.map +1 -0
- package/dist/test/adapter-factory/profile-rename-joins.d.ts +73 -0
- package/dist/test/adapter-factory/profile-rename-joins.d.ts.map +1 -0
- package/dist/test/adapter-factory/profile-rename-joins.js +34 -0
- package/dist/test/adapter-factory/profile-rename-joins.js.map +1 -0
- package/dist/test/adapter-factory/transactions.d.ts +21 -0
- package/dist/test/adapter-factory/transactions.d.ts.map +1 -0
- package/dist/test/adapter-factory/transactions.js +28 -0
- package/dist/test/adapter-factory/transactions.js.map +1 -0
- package/dist/test/adapter-factory/uuid.d.ts +18 -0
- package/dist/test/adapter-factory/uuid.d.ts.map +1 -0
- package/dist/test/adapter-factory/uuid.js +58 -0
- package/dist/test/adapter-factory/uuid.js.map +1 -0
- package/dist/utils/index.d.ts +18 -3
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js.map +1 -1
- package/package.json +8 -4
- package/src/auth-options.ts +0 -2
- package/src/client/adapter-utils.ts +80 -73
- package/src/client/adapter.test.ts +2 -74
- package/src/client/adapter.ts +142 -7
- package/src/client/create-api.ts +1 -0
- package/src/client/create-client.ts +14 -6
- package/src/client/create-schema.ts +0 -1
- package/src/component/_generated/api.ts +12 -0
- package/src/component/_generated/component.ts +19454 -215
- package/src/component/adapterTest.ts +250 -466
- package/src/component/schema.ts +21 -26
- package/src/component/testProfiles/adapterAdditionalFields.ts +13 -0
- package/src/component/testProfiles/adapterOrganizationJoins.ts +13 -0
- package/src/component/testProfiles/adapterPluginTable.ts +13 -0
- package/src/component/testProfiles/adapterRenameField.ts +13 -0
- package/src/component/testProfiles/adapterRenameUserCustom.ts +13 -0
- package/src/component/testProfiles/adapterRenameUserTable.ts +13 -0
- package/src/component/testProfiles/auth-options.profile-additional-fields.ts +39 -0
- package/src/component/testProfiles/auth-options.profile-plugin-table.ts +93 -0
- package/src/component/testProfiles/auth-options.profile-rename-joins.ts +54 -0
- package/src/component/testProfiles/schema.profile-additional-fields.ts +39 -0
- package/src/component/testProfiles/schema.profile-plugin-table.ts +130 -0
- package/src/nextjs/index.ts +1 -0
- package/src/plugins/convex/index.test.ts +55 -0
- package/src/plugins/convex/index.ts +26 -11
- package/src/plugins/cross-domain/index.test.ts +67 -0
- package/src/plugins/cross-domain/index.ts +10 -21
- package/src/react-start/index.ts +1 -0
- package/src/test/adapter-factory/auth-flow.ts +170 -0
- package/src/test/adapter-factory/basic.ts +3190 -0
- package/src/test/adapter-factory/convex-custom.ts +706 -0
- package/src/test/adapter-factory/index.ts +10 -0
- package/src/test/adapter-factory/joins.ts +28 -0
- package/src/test/adapter-factory/number-id.ts +45 -0
- package/src/test/adapter-factory/profile-additional-fields.ts +84 -0
- package/src/test/adapter-factory/profile-plugin-table.ts +37 -0
- package/src/test/adapter-factory/profile-rename-joins.ts +67 -0
- package/src/test/adapter-factory/transactions.ts +38 -0
- package/src/test/adapter-factory/uuid.ts +67 -0
- package/src/utils/index.ts +25 -3
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createTestSuite } from "@better-auth/test-utils/adapter";
|
|
2
|
+
import { expect } from "vitest";
|
|
3
|
+
import { getNormalTestSuiteTests } from "./basic.js";
|
|
4
|
+
|
|
5
|
+
export const joinsTestSuite = createTestSuite(
|
|
6
|
+
"joins",
|
|
7
|
+
{
|
|
8
|
+
defaultBetterAuthOptions: {
|
|
9
|
+
experimental: {
|
|
10
|
+
joins: true,
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
alwaysMigrate: true,
|
|
14
|
+
prefixTests: "joins",
|
|
15
|
+
},
|
|
16
|
+
(helpers) => {
|
|
17
|
+
const { "create - should use generateId if provided": _, ...normalTests } =
|
|
18
|
+
getNormalTestSuiteTests({ ...helpers });
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
"init - tests": async () => {
|
|
22
|
+
const opts = helpers.getBetterAuthOptions();
|
|
23
|
+
expect(opts.experimental?.joins).toBe(true);
|
|
24
|
+
},
|
|
25
|
+
...normalTests,
|
|
26
|
+
};
|
|
27
|
+
},
|
|
28
|
+
);
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { createTestSuite } from "@better-auth/test-utils/adapter";
|
|
2
|
+
import type { User } from "better-auth/types";
|
|
3
|
+
import { expect } from "vitest";
|
|
4
|
+
import { getNormalTestSuiteTests } from "./basic.js";
|
|
5
|
+
|
|
6
|
+
export const numberIdTestSuite = createTestSuite(
|
|
7
|
+
"number-id",
|
|
8
|
+
{
|
|
9
|
+
defaultBetterAuthOptions: {
|
|
10
|
+
advanced: {
|
|
11
|
+
database: {
|
|
12
|
+
generateId: "serial",
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
alwaysMigrate: true,
|
|
17
|
+
prefixTests: "number-id",
|
|
18
|
+
},
|
|
19
|
+
(helpers) => {
|
|
20
|
+
const { "create - should use generateId if provided": _, ...normalTests } =
|
|
21
|
+
getNormalTestSuiteTests({ ...helpers });
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
"init - tests": async () => {
|
|
25
|
+
const opts = helpers.getBetterAuthOptions();
|
|
26
|
+
expect(
|
|
27
|
+
(opts.advanced?.database as any)?.useNumberId ||
|
|
28
|
+
opts.advanced?.database?.generateId === "serial",
|
|
29
|
+
).toBe(true);
|
|
30
|
+
},
|
|
31
|
+
"create - should return a number id": async () => {
|
|
32
|
+
const user = await helpers.generate("user");
|
|
33
|
+
const res = await helpers.adapter.create<User>({
|
|
34
|
+
model: "user",
|
|
35
|
+
data: user,
|
|
36
|
+
forceAllowId: true,
|
|
37
|
+
});
|
|
38
|
+
expect(res).toHaveProperty("id");
|
|
39
|
+
expect(typeof res.id).toBe("string");
|
|
40
|
+
expect(Number(res.id)).toBeGreaterThan(0);
|
|
41
|
+
},
|
|
42
|
+
...normalTests,
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
);
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { createTestSuite } from "@better-auth/test-utils/adapter";
|
|
2
|
+
import { expect } from "vitest";
|
|
3
|
+
import { getNormalTestSuiteTests } from "./basic.js";
|
|
4
|
+
import {
|
|
5
|
+
AUTH_FLOW_DEFAULT_BETTER_AUTH_OPTIONS,
|
|
6
|
+
getAuthFlowSuiteTests,
|
|
7
|
+
} from "./auth-flow.js";
|
|
8
|
+
|
|
9
|
+
export const ADDITIONAL_FIELDS_NORMAL_TESTS = [
|
|
10
|
+
"deleteMany - should delete many models with numeric values",
|
|
11
|
+
"findMany - should find many models with sortBy",
|
|
12
|
+
"findMany - should find many models with sortBy and limit",
|
|
13
|
+
"findMany - should find many with join and sortBy",
|
|
14
|
+
"findOne - should find a model with additional fields",
|
|
15
|
+
] as const;
|
|
16
|
+
|
|
17
|
+
export const ADDITIONAL_FIELDS_AUTH_FLOW_TEST =
|
|
18
|
+
"should sign up with additional fields" as const;
|
|
19
|
+
|
|
20
|
+
const pickTests = (
|
|
21
|
+
tests: ReturnType<typeof getNormalTestSuiteTests>,
|
|
22
|
+
testNames: readonly string[],
|
|
23
|
+
) =>
|
|
24
|
+
Object.fromEntries(
|
|
25
|
+
Object.entries(tests).filter(([testName]) => testNames.includes(testName)),
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
const omitTests = (
|
|
29
|
+
tests: ReturnType<typeof getNormalTestSuiteTests>,
|
|
30
|
+
testNames: readonly string[],
|
|
31
|
+
) =>
|
|
32
|
+
Object.fromEntries(
|
|
33
|
+
Object.entries(tests).filter(([testName]) => !testNames.includes(testName)),
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
export const coreNormalTestSuite = createTestSuite(
|
|
37
|
+
"normal",
|
|
38
|
+
{},
|
|
39
|
+
(helpers, debugTools) => {
|
|
40
|
+
const tests = getNormalTestSuiteTests(helpers, debugTools);
|
|
41
|
+
return {
|
|
42
|
+
"init - tests": async () => {
|
|
43
|
+
const opts = helpers.getBetterAuthOptions();
|
|
44
|
+
expect(opts.advanced?.database?.generateId !== "serial").toBeTruthy();
|
|
45
|
+
},
|
|
46
|
+
...omitTests(tests, ADDITIONAL_FIELDS_NORMAL_TESTS),
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
export const additionalFieldsNormalTestSuite = createTestSuite(
|
|
52
|
+
"normal-additional-fields",
|
|
53
|
+
{},
|
|
54
|
+
(helpers, debugTools) => {
|
|
55
|
+
const tests = getNormalTestSuiteTests(helpers, debugTools);
|
|
56
|
+
return pickTests(tests, ADDITIONAL_FIELDS_NORMAL_TESTS);
|
|
57
|
+
},
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
export const coreAuthFlowTestSuite = createTestSuite(
|
|
61
|
+
"auth-flow",
|
|
62
|
+
{
|
|
63
|
+
defaultBetterAuthOptions: AUTH_FLOW_DEFAULT_BETTER_AUTH_OPTIONS,
|
|
64
|
+
},
|
|
65
|
+
(helpers) => {
|
|
66
|
+
const tests = getAuthFlowSuiteTests(helpers);
|
|
67
|
+
const { [ADDITIONAL_FIELDS_AUTH_FLOW_TEST]: _skip, ...remaining } = tests;
|
|
68
|
+
return remaining;
|
|
69
|
+
},
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
export const additionalFieldsAuthFlowTestSuite = createTestSuite(
|
|
73
|
+
"auth-flow-additional-fields",
|
|
74
|
+
{
|
|
75
|
+
defaultBetterAuthOptions: AUTH_FLOW_DEFAULT_BETTER_AUTH_OPTIONS,
|
|
76
|
+
},
|
|
77
|
+
(helpers) => {
|
|
78
|
+
const tests = getAuthFlowSuiteTests(helpers);
|
|
79
|
+
return {
|
|
80
|
+
[ADDITIONAL_FIELDS_AUTH_FLOW_TEST]:
|
|
81
|
+
tests[ADDITIONAL_FIELDS_AUTH_FLOW_TEST],
|
|
82
|
+
};
|
|
83
|
+
},
|
|
84
|
+
);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { createTestSuite } from "@better-auth/test-utils/adapter";
|
|
2
|
+
import { getNormalTestSuiteTests } from "./basic.js";
|
|
3
|
+
|
|
4
|
+
export const PLUGIN_TABLE_NORMAL_TESTS = [
|
|
5
|
+
"create - should apply default values to fields",
|
|
6
|
+
"create - should return null for nullable foreign keys",
|
|
7
|
+
"create - should support arrays",
|
|
8
|
+
"create - should support json",
|
|
9
|
+
"findMany - should find many with both one-to-one and one-to-many joins",
|
|
10
|
+
"findMany - should find many with one-to-one join",
|
|
11
|
+
"findMany - should handle mixed joins correctly when some are missing",
|
|
12
|
+
"findMany - should return empty array when base records don't exist with joins",
|
|
13
|
+
"findMany - should return null for one-to-one join when joined records don't exist",
|
|
14
|
+
"findMany - should select fields with one-to-one join",
|
|
15
|
+
"findOne - should not apply defaultValue if value not found",
|
|
16
|
+
"findOne - should return an object for one-to-one joins",
|
|
17
|
+
"findOne - should return null for one-to-one join when joined record doesn't exist",
|
|
18
|
+
"findOne - should select fields with one-to-one join",
|
|
19
|
+
"findOne - should work with both one-to-one and one-to-many joins",
|
|
20
|
+
] as const;
|
|
21
|
+
|
|
22
|
+
const pickTests = (
|
|
23
|
+
tests: ReturnType<typeof getNormalTestSuiteTests>,
|
|
24
|
+
testNames: readonly string[],
|
|
25
|
+
) =>
|
|
26
|
+
Object.fromEntries(
|
|
27
|
+
Object.entries(tests).filter(([testName]) => testNames.includes(testName)),
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
export const pluginTableNormalTestSuite = createTestSuite(
|
|
31
|
+
"normal-plugin-table",
|
|
32
|
+
{},
|
|
33
|
+
(helpers, debugTools) => {
|
|
34
|
+
const tests = getNormalTestSuiteTests(helpers, debugTools);
|
|
35
|
+
return pickTests(tests, PLUGIN_TABLE_NORMAL_TESTS);
|
|
36
|
+
},
|
|
37
|
+
);
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { createTestSuite } from "@better-auth/test-utils/adapter";
|
|
2
|
+
import { getNormalTestSuiteTests } from "./basic.js";
|
|
3
|
+
|
|
4
|
+
const pickTests = (
|
|
5
|
+
tests: ReturnType<typeof getNormalTestSuiteTests>,
|
|
6
|
+
testNames: readonly string[],
|
|
7
|
+
) =>
|
|
8
|
+
Object.fromEntries(
|
|
9
|
+
Object.entries(tests).filter(([testName]) => testNames.includes(testName)),
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
export const RENAME_FIELD_AND_JOIN_TESTS = [
|
|
13
|
+
"findOne - should find a model with modified field name",
|
|
14
|
+
"findOne - should join a model with modified field name",
|
|
15
|
+
"findOne - should return null for failed base model lookup that has joins",
|
|
16
|
+
] as const;
|
|
17
|
+
|
|
18
|
+
export const RENAME_MODEL_USER_CUSTOM_TEST =
|
|
19
|
+
"findOne - should find a model with modified model name" as const;
|
|
20
|
+
|
|
21
|
+
export const RENAME_MODEL_USER_TABLE_TEST =
|
|
22
|
+
"findOne - backwards join with modified field name (session base, users-table join)" as const;
|
|
23
|
+
|
|
24
|
+
export const MULTI_JOINS_MISSING_ROWS_TEST =
|
|
25
|
+
"findOne - multiple joins should return result even when some joined tables have no matching rows" as const;
|
|
26
|
+
|
|
27
|
+
export const renameFieldAndJoinTestSuite = createTestSuite(
|
|
28
|
+
"normal-rename-field-and-join",
|
|
29
|
+
{},
|
|
30
|
+
(helpers, debugTools) => {
|
|
31
|
+
const tests = getNormalTestSuiteTests(helpers, debugTools);
|
|
32
|
+
return pickTests(tests, RENAME_FIELD_AND_JOIN_TESTS);
|
|
33
|
+
},
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
export const renameModelUserCustomTestSuite = createTestSuite(
|
|
37
|
+
"normal-rename-model-user-custom",
|
|
38
|
+
{},
|
|
39
|
+
(helpers, debugTools) => {
|
|
40
|
+
const tests = getNormalTestSuiteTests(helpers, debugTools);
|
|
41
|
+
return {
|
|
42
|
+
[RENAME_MODEL_USER_CUSTOM_TEST]: tests[RENAME_MODEL_USER_CUSTOM_TEST],
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
export const renameModelUserTableTestSuite = createTestSuite(
|
|
48
|
+
"normal-rename-model-user-table",
|
|
49
|
+
{},
|
|
50
|
+
(helpers, debugTools) => {
|
|
51
|
+
const tests = getNormalTestSuiteTests(helpers, debugTools);
|
|
52
|
+
return {
|
|
53
|
+
[RENAME_MODEL_USER_TABLE_TEST]: tests[RENAME_MODEL_USER_TABLE_TEST],
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
export const multiJoinsMissingRowsTestSuite = createTestSuite(
|
|
59
|
+
"normal-multi-joins-missing-rows",
|
|
60
|
+
{},
|
|
61
|
+
(helpers, debugTools) => {
|
|
62
|
+
const tests = getNormalTestSuiteTests(helpers, debugTools);
|
|
63
|
+
return {
|
|
64
|
+
[MULTI_JOINS_MISSING_ROWS_TEST]: tests[MULTI_JOINS_MISSING_ROWS_TEST],
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { createTestSuite } from "@better-auth/test-utils/adapter";
|
|
2
|
+
import type { User } from "better-auth/db";
|
|
3
|
+
import { expect } from "vitest";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* This test suite tests the transaction functionality of the adapter.
|
|
7
|
+
*/
|
|
8
|
+
export const transactionsTestSuite = createTestSuite(
|
|
9
|
+
"transactions",
|
|
10
|
+
{},
|
|
11
|
+
({ adapter, generate, hardCleanup }) => ({
|
|
12
|
+
"transaction - should rollback failing transaction": async ({ skip }) => {
|
|
13
|
+
const isEnabled = adapter.options?.adapterConfig.transaction;
|
|
14
|
+
if (!isEnabled) {
|
|
15
|
+
skip(
|
|
16
|
+
`Skipping test: ${adapter.options?.adapterConfig.adapterName} does not support transactions`,
|
|
17
|
+
);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const user1 = await generate("user");
|
|
22
|
+
await expect(
|
|
23
|
+
adapter.transaction(async (tx) => {
|
|
24
|
+
await tx.create({ model: "user", data: user1, forceAllowId: true });
|
|
25
|
+
const users = await tx.findMany({ model: "user" });
|
|
26
|
+
expect(users).toHaveLength(1);
|
|
27
|
+
throw new Error("Simulated failure");
|
|
28
|
+
}),
|
|
29
|
+
).rejects.toThrow("Simulated failure");
|
|
30
|
+
const result = await adapter.findMany<User>({
|
|
31
|
+
model: "user",
|
|
32
|
+
});
|
|
33
|
+
//Transactions made rows are unable to be automatically cleaned up, so we need to clean them up manually
|
|
34
|
+
await hardCleanup();
|
|
35
|
+
expect(result.length).toBe(0);
|
|
36
|
+
},
|
|
37
|
+
}),
|
|
38
|
+
);
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { User } from "@better-auth/core/db";
|
|
2
|
+
import { createTestSuite } from "@better-auth/test-utils/adapter";
|
|
3
|
+
import { expect } from "vitest";
|
|
4
|
+
import { getNormalTestSuiteTests } from "./basic.js";
|
|
5
|
+
|
|
6
|
+
export const uuidTestSuite = createTestSuite(
|
|
7
|
+
"uuid",
|
|
8
|
+
{
|
|
9
|
+
defaultBetterAuthOptions: {
|
|
10
|
+
advanced: {
|
|
11
|
+
database: {
|
|
12
|
+
generateId: "uuid",
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
prefixTests: "uuid",
|
|
17
|
+
alwaysMigrate: true,
|
|
18
|
+
// This is here to overwrite `generateId` functions to generate UUIDs instead of the default.
|
|
19
|
+
// Since existing tests often use generated IDs as well as `forceAllowId` to be true, this is needed to ensure the tests pass.
|
|
20
|
+
customIdGenerator() {
|
|
21
|
+
return crypto.randomUUID();
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
(helpers) => {
|
|
25
|
+
const { "create - should use generateId if provided": _, ...normalTests } =
|
|
26
|
+
getNormalTestSuiteTests(helpers);
|
|
27
|
+
return {
|
|
28
|
+
"init - tests": async () => {
|
|
29
|
+
const opts = helpers.getBetterAuthOptions();
|
|
30
|
+
expect(opts.advanced?.database?.generateId === "uuid").toBe(true);
|
|
31
|
+
},
|
|
32
|
+
"create - should return a uuid": async () => {
|
|
33
|
+
const user = await helpers.generate("user");
|
|
34
|
+
const res = await helpers.adapter.create<User>({
|
|
35
|
+
model: "user",
|
|
36
|
+
data: {
|
|
37
|
+
...user,
|
|
38
|
+
//@ts-expect-error - remove id from `user`
|
|
39
|
+
id: undefined,
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
expect(res).toHaveProperty("id");
|
|
43
|
+
expect(typeof res.id).toBe("string");
|
|
44
|
+
const uuidRegex =
|
|
45
|
+
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
46
|
+
expect(res.id).toMatch(uuidRegex);
|
|
47
|
+
},
|
|
48
|
+
"findOne - should find a model using a uuid": async () => {
|
|
49
|
+
const { id: _, ...user } = await helpers.generate("user");
|
|
50
|
+
const res = await helpers.adapter.create<User>({
|
|
51
|
+
model: "user",
|
|
52
|
+
data: user,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const result = await helpers.adapter.findOne<User>({
|
|
56
|
+
model: "user",
|
|
57
|
+
where: [{ field: "id", value: res.id }],
|
|
58
|
+
});
|
|
59
|
+
const uuidRegex =
|
|
60
|
+
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
61
|
+
expect(result?.id).toMatch(uuidRegex);
|
|
62
|
+
expect(result).toEqual(res);
|
|
63
|
+
},
|
|
64
|
+
...normalTests,
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
);
|
package/src/utils/index.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { betterFetch } from "@better-fetch/fetch";
|
|
2
|
-
import type { Auth } from "better-auth";
|
|
3
|
-
import type { betterAuth } from "better-auth/minimal";
|
|
4
2
|
import { getSessionCookie } from "better-auth/cookies";
|
|
5
3
|
import type {
|
|
6
4
|
AuthProvider,
|
|
@@ -15,9 +13,33 @@ import { JWT_COOKIE_NAME } from "../plugins/convex/index.js";
|
|
|
15
13
|
import * as jose from "jose";
|
|
16
14
|
import type { Jwk } from "better-auth/plugins/jwt";
|
|
17
15
|
|
|
16
|
+
type TrustedOriginsOption =
|
|
17
|
+
| (string | null | undefined)[]
|
|
18
|
+
| ((
|
|
19
|
+
request?: Request
|
|
20
|
+
) =>
|
|
21
|
+
| (string | null | undefined)[]
|
|
22
|
+
| Promise<(string | null | undefined)[]>);
|
|
23
|
+
|
|
24
|
+
type RegisterableAuth = {
|
|
25
|
+
handler: (request: Request) => Promise<Response>;
|
|
26
|
+
options: {
|
|
27
|
+
baseURL?: string;
|
|
28
|
+
basePath?: string;
|
|
29
|
+
trustedOrigins?: TrustedOriginsOption;
|
|
30
|
+
[key: string]: unknown;
|
|
31
|
+
};
|
|
32
|
+
$context: Promise<{
|
|
33
|
+
options: {
|
|
34
|
+
trustedOrigins?: TrustedOriginsOption;
|
|
35
|
+
[key: string]: unknown;
|
|
36
|
+
};
|
|
37
|
+
}>;
|
|
38
|
+
};
|
|
39
|
+
|
|
18
40
|
export type CreateAuth<
|
|
19
41
|
DataModel extends GenericDataModel,
|
|
20
|
-
A extends
|
|
42
|
+
A extends RegisterableAuth = RegisterableAuth,
|
|
21
43
|
> = (ctx: GenericCtx<DataModel>) => A;
|
|
22
44
|
|
|
23
45
|
export type EventFunction<T extends DefaultFunctionArgs> = FunctionReference<
|