@convex-dev/better-auth 0.11.3 → 0.11.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.
Files changed (65) hide show
  1. package/dist/component/_generated/component.d.ts +0 -1
  2. package/dist/component/_generated/component.d.ts.map +1 -1
  3. package/dist/component/adapterTest.d.ts +0 -1
  4. package/dist/component/adapterTest.d.ts.map +1 -1
  5. package/dist/component/adapterTest.js +11 -21
  6. package/dist/component/adapterTest.js.map +1 -1
  7. package/dist/plugins/convex/index.d.ts +1 -1
  8. package/dist/plugins/convex/index.d.ts.map +1 -1
  9. package/dist/plugins/cross-domain/index.d.ts.map +1 -1
  10. package/dist/test/adapter-factory/auth-flow.d.ts +1 -21
  11. package/dist/test/adapter-factory/auth-flow.d.ts.map +1 -1
  12. package/dist/test/adapter-factory/auth-flow.js +32 -37
  13. package/dist/test/adapter-factory/auth-flow.js.map +1 -1
  14. package/dist/test/adapter-factory/basic.d.ts +11 -34
  15. package/dist/test/adapter-factory/basic.d.ts.map +1 -1
  16. package/dist/test/adapter-factory/basic.js +54 -2626
  17. package/dist/test/adapter-factory/basic.js.map +1 -1
  18. package/dist/test/adapter-factory/index.d.ts +0 -6
  19. package/dist/test/adapter-factory/index.d.ts.map +1 -1
  20. package/dist/test/adapter-factory/index.js +0 -6
  21. package/dist/test/adapter-factory/index.js.map +1 -1
  22. package/dist/test/adapter-factory/profile-additional-fields.d.ts.map +1 -1
  23. package/dist/test/adapter-factory/profile-additional-fields.js +14 -1
  24. package/dist/test/adapter-factory/profile-additional-fields.js.map +1 -1
  25. package/dist/test/adapter-factory/profile-plugin-table.d.ts.map +1 -1
  26. package/dist/test/adapter-factory/profile-plugin-table.js +8 -1
  27. package/dist/test/adapter-factory/profile-plugin-table.js.map +1 -1
  28. package/dist/test/adapter-factory/profile-rename-joins.d.ts +3 -3
  29. package/dist/test/adapter-factory/profile-rename-joins.d.ts.map +1 -1
  30. package/dist/test/adapter-factory/profile-rename-joins.js +11 -10
  31. package/dist/test/adapter-factory/profile-rename-joins.js.map +1 -1
  32. package/dist/utils/index.d.ts +2 -1
  33. package/dist/utils/index.d.ts.map +1 -1
  34. package/dist/utils/index.js.map +1 -1
  35. package/package.json +4 -6
  36. package/src/client/adapter.test.ts +20 -5
  37. package/src/component/_generated/component.ts +0 -1
  38. package/src/component/adapterTest.ts +12 -26
  39. package/src/test/adapter-factory/auth-flow.ts +146 -160
  40. package/src/test/adapter-factory/basic.ts +185 -3187
  41. package/src/test/adapter-factory/index.ts +0 -6
  42. package/src/test/adapter-factory/profile-additional-fields.ts +75 -57
  43. package/src/test/adapter-factory/profile-plugin-table.ts +10 -2
  44. package/src/test/adapter-factory/profile-rename-joins.ts +13 -11
  45. package/src/utils/index.ts +2 -1
  46. package/dist/test/adapter-factory/joins.d.ts +0 -18
  47. package/dist/test/adapter-factory/joins.d.ts.map +0 -1
  48. package/dist/test/adapter-factory/joins.js +0 -22
  49. package/dist/test/adapter-factory/joins.js.map +0 -1
  50. package/dist/test/adapter-factory/number-id.d.ts +0 -18
  51. package/dist/test/adapter-factory/number-id.d.ts.map +0 -1
  52. package/dist/test/adapter-factory/number-id.js +0 -36
  53. package/dist/test/adapter-factory/number-id.js.map +0 -1
  54. package/dist/test/adapter-factory/transactions.d.ts +0 -21
  55. package/dist/test/adapter-factory/transactions.d.ts.map +0 -1
  56. package/dist/test/adapter-factory/transactions.js +0 -28
  57. package/dist/test/adapter-factory/transactions.js.map +0 -1
  58. package/dist/test/adapter-factory/uuid.d.ts +0 -18
  59. package/dist/test/adapter-factory/uuid.d.ts.map +0 -1
  60. package/dist/test/adapter-factory/uuid.js +0 -58
  61. package/dist/test/adapter-factory/uuid.js.map +0 -1
  62. package/src/test/adapter-factory/joins.ts +0 -28
  63. package/src/test/adapter-factory/number-id.ts +0 -45
  64. package/src/test/adapter-factory/transactions.ts +0 -38
  65. package/src/test/adapter-factory/uuid.ts +0 -67
@@ -13,11 +13,18 @@ import type { ComponentApi } from "./_generated/component.js";
13
13
  // globals are available through dynamic imports.
14
14
 
15
15
  const NORMAL_DISABLED_TESTS = [
16
+ // dynamic-schema-plugin-table/dynamic-schema-additional-fields:
17
+ // Convex validators are static in this harness, so runtime schema mutation
18
+ // tests are validated in dedicated profiles instead.
16
19
  "create - should apply default values to fields",
17
20
  "create - should return null for nullable foreign keys",
18
21
  "create - should support arrays",
19
22
  "create - should support json",
23
+ // convex-id-generation:
24
+ // Convex controls generated IDs at write time.
20
25
  "create - should use generateId if provided",
26
+ // offset-unsupported:
27
+ // Convex adapter rejects offset pagination.
21
28
  "findMany - should be able to perform a complex limited join",
22
29
  "findMany - should find many models with limit and offset",
23
30
  "findMany - should find many models with offset",
@@ -32,6 +39,8 @@ const NORMAL_DISABLED_TESTS = [
32
39
  "findMany - should return empty array when base records don't exist with joins",
33
40
  "findMany - should return null for one-to-one join when joined records don't exist",
34
41
  "findMany - should select fields with one-to-one join",
42
+ // profile-specific coverage:
43
+ // These are intentionally exercised in dedicated profile suites.
35
44
  "findOne - backwards join with modified field name (session base, users-table join)",
36
45
  "findOne - multiple joins should return result even when some joined tables have no matching rows",
37
46
  "findOne - should find a model with modified field name",
@@ -102,7 +111,9 @@ const organizationJoinsProfileApi = profileApi("adapterOrganizationJoins");
102
111
  export const runTests = action(
103
112
  async (ctx: GenericActionCtx<DataModel>, _args: EmptyObject) => {
104
113
  const testUtilsImport = "@better-auth/test-utils/adapter";
105
- const { testAdapter } = await import(testUtilsImport);
114
+ const { testAdapter, transactionsTestSuite, uuidTestSuite } = await import(
115
+ testUtilsImport
116
+ );
106
117
  const adapterFactoryImport = "../test/adapter-factory/index.js";
107
118
  const {
108
119
  coreNormalTestSuite,
@@ -114,8 +125,6 @@ export const runTests = action(
114
125
  renameModelUserCustomTestSuite,
115
126
  renameModelUserTableTestSuite,
116
127
  multiJoinsMissingRowsTestSuite,
117
- transactionsTestSuite,
118
- uuidTestSuite,
119
128
  convexCustomTestSuite,
120
129
  } = await import(adapterFactoryImport);
121
130
 
@@ -264,26 +273,3 @@ export const runTests = action(
264
273
  await executeOrganizationJoinsProfile();
265
274
  }
266
275
  );
267
-
268
- // Keep this export during migration to avoid breaking generated component types.
269
- export const runCustomTests = action(
270
- async (ctx: GenericActionCtx<DataModel>, _args: EmptyObject) => {
271
- const testUtilsImport = "@better-auth/test-utils/adapter";
272
- const { testAdapter } = await import(testUtilsImport);
273
- const adapterFactoryImport = "../test/adapter-factory/index.js";
274
- const { convexCustomTestSuite } = await import(adapterFactoryImport);
275
- const authComponent = createClient<DataModel>(baseProfileApi, {
276
- verbose: false,
277
- });
278
-
279
- const { execute } = await testAdapter({
280
- adapter: () => {
281
- return authComponent.adapter(ctx);
282
- },
283
- runMigrations: () => {},
284
- overrideBetterAuthOptions: getOverrideBetterAuthOptions,
285
- tests: [convexCustomTestSuite()],
286
- });
287
- await execute();
288
- }
289
- );
@@ -1,170 +1,156 @@
1
1
  import type { Session, User } from "@better-auth/core/db";
2
- import { createTestSuite } from "@better-auth/test-utils/adapter";
2
+ import type { createTestSuite } from "@better-auth/test-utils/adapter";
3
3
  import { setCookieToHeader } from "better-auth/cookies";
4
4
  import { expect } from "vitest";
5
5
 
6
6
  export const AUTH_FLOW_DEFAULT_BETTER_AUTH_OPTIONS = {
7
- emailAndPassword: {
8
- enabled: true,
9
- password: {
10
- hash: async (password: string) => password,
11
- async verify(data: { hash: string; password: string }) {
12
- return data.hash === data.password;
13
- },
14
- },
15
- },
7
+ emailAndPassword: {
8
+ enabled: true,
9
+ password: {
10
+ hash: async (password: string) => password,
11
+ async verify(data: { hash: string; password: string }) {
12
+ return data.hash === data.password;
13
+ },
14
+ },
15
+ },
16
16
  };
17
17
 
18
18
  export const getAuthFlowSuiteTests = (
19
- {
20
- generate,
21
- getAuth,
22
- modifyBetterAuthOptions,
23
- tryCatch,
24
- }: Parameters<Parameters<typeof createTestSuite>[2]>[0],
19
+ {
20
+ generate,
21
+ getAuth,
22
+ modifyBetterAuthOptions,
23
+ tryCatch,
24
+ }: Parameters<Parameters<typeof createTestSuite>[2]>[0],
25
25
  ) => ({
26
- "should successfully sign up": async () => {
27
- const auth = await getAuth();
28
- const user = await generate("user");
29
- const result = await auth.api.signUpEmail({
30
- body: {
31
- email: user.email,
32
- password: crypto.randomUUID(),
33
- name: user.name,
34
- image: user.image || "",
35
- },
36
- });
37
- expect(result.user).toBeDefined();
38
- expect(result.user.email).toBe(user.email);
39
- expect(result.user.name).toBe(user.name);
40
- expect(result.user.image).toBe(user.image || "");
41
- expect(result.user.emailVerified).toBe(false);
42
- expect(result.user.createdAt).toBeDefined();
43
- expect(result.user.updatedAt).toBeDefined();
44
- },
45
- "should successfully sign in": async () => {
46
- const auth = await getAuth();
47
- const user = await generate("user");
48
- const password = crypto.randomUUID();
49
- const signUpResult = await auth.api.signUpEmail({
50
- body: {
51
- email: user.email,
52
- password: password,
53
- name: user.name,
54
- image: user.image || "",
55
- },
56
- });
57
- const result = await auth.api.signInEmail({
58
- body: { email: user.email, password: password },
59
- });
60
- expect(result.user).toBeDefined();
61
- expect(result.user.id).toBe(signUpResult.user.id);
62
- },
63
- "should successfully get session": async () => {
64
- const auth = await getAuth();
65
- const user = await generate("user");
66
- const password = crypto.randomUUID();
67
- const response = await auth.api.signUpEmail({
68
- body: {
69
- email: user.email,
70
- password: password,
71
- name: user.name,
72
- image: user.image || "",
73
- },
74
- asResponse: true,
75
- });
76
- const headers = new Headers();
77
- setCookieToHeader(headers)({ response });
78
- const result = await auth.api.getSession({
79
- headers,
80
- });
81
- const signUpResult = (await response.json()) as {
82
- user: User;
83
- session: Session;
84
- };
85
- signUpResult.user.createdAt = new Date(signUpResult.user.createdAt).getTime() as unknown as Date;
86
- signUpResult.user.updatedAt = new Date(signUpResult.user.updatedAt).getTime() as unknown as Date;
87
- expect(result?.user).toBeDefined();
88
- expect(result?.user).toStrictEqual(signUpResult.user);
89
- expect(result?.session).toBeDefined();
90
- },
91
- "should not sign in with invalid email": async () => {
92
- const auth = await getAuth();
93
- const user = await generate("user");
94
- const { data, error } = await tryCatch(
95
- auth.api.signInEmail({
96
- body: { email: user.email, password: crypto.randomUUID() },
97
- }),
98
- );
99
- expect(data).toBeNull();
100
- expect(error).toBeDefined();
101
- },
102
- "should store and retrieve timestamps correctly across timezones": async () => {
103
- using _ = recoverProcessTZ();
104
- const auth = await getAuth();
105
- const user = await generate("user");
106
- const password = crypto.randomUUID();
107
- const userSignUp = await auth.api.signUpEmail({
108
- body: {
109
- email: user.email,
110
- password: password,
111
- name: user.name,
112
- image: user.image || "",
113
- },
114
- });
115
- process.env.TZ = "Europe/London";
116
- const userSignIn = await auth.api.signInEmail({
117
- body: { email: user.email, password: password },
118
- });
119
- process.env.TZ = "America/Los_Angeles";
120
- expect(userSignUp.user.createdAt).toStrictEqual(
121
- userSignIn.user.createdAt,
122
- );
123
- },
124
- "should sign up with additional fields": async () => {
125
- await modifyBetterAuthOptions(
126
- { user: { additionalFields: { dateField: { type: "date" } } } },
127
- true,
128
- );
129
- const auth = await getAuth();
130
- const user = await generate("user");
131
- const dateField = new Date();
132
- const response = await auth.api.signUpEmail({
133
- body: {
134
- email: user.email,
135
- name: user.name,
136
- password: crypto.randomUUID(),
137
- //@ts-expect-error - we are testing with additional fields
138
- dateField: dateField.toISOString(), // using iso string to simulate client to server communication
139
- },
140
- asResponse: true,
141
- });
142
- const headers = new Headers();
143
- setCookieToHeader(headers)({ response });
144
- const result = await auth.api.getSession({
145
- headers,
146
- });
147
- //@ts-expect-error - we are testing with additional fields
148
- expect(result?.user.dateField).toStrictEqual(dateField.getTime());
149
- },
26
+ "should successfully sign up": async () => {
27
+ const auth = await getAuth();
28
+ const user = await generate("user");
29
+ const result = await auth.api.signUpEmail({
30
+ body: {
31
+ email: user.email,
32
+ password: crypto.randomUUID(),
33
+ name: user.name,
34
+ image: user.image || "",
35
+ },
36
+ });
37
+ expect(result.user).toBeDefined();
38
+ expect(result.user.email).toBe(user.email);
39
+ expect(result.user.name).toBe(user.name);
40
+ expect(result.user.image).toBe(user.image || "");
41
+ expect(result.user.emailVerified).toBe(false);
42
+ expect(result.user.createdAt).toBeDefined();
43
+ expect(result.user.updatedAt).toBeDefined();
44
+ },
45
+ "should successfully sign in": async () => {
46
+ const auth = await getAuth();
47
+ const user = await generate("user");
48
+ const password = crypto.randomUUID();
49
+ const signUpResult = await auth.api.signUpEmail({
50
+ body: {
51
+ email: user.email,
52
+ password,
53
+ name: user.name,
54
+ image: user.image || "",
55
+ },
56
+ });
57
+ const result = await auth.api.signInEmail({
58
+ body: { email: user.email, password },
59
+ });
60
+ expect(result.user).toBeDefined();
61
+ expect(result.user.id).toBe(signUpResult.user.id);
62
+ },
63
+ "should successfully get session": async () => {
64
+ const auth = await getAuth();
65
+ const user = await generate("user");
66
+ const password = crypto.randomUUID();
67
+ const response = await auth.api.signUpEmail({
68
+ body: {
69
+ email: user.email,
70
+ password,
71
+ name: user.name,
72
+ image: user.image || "",
73
+ },
74
+ asResponse: true,
75
+ });
76
+ const headers = new Headers();
77
+ setCookieToHeader(headers)({ response });
78
+ const result = await auth.api.getSession({
79
+ headers,
80
+ });
81
+ const signUpResult = (await response.json()) as {
82
+ user: User;
83
+ session: Session;
84
+ };
85
+ signUpResult.user.createdAt = new Date(signUpResult.user.createdAt).getTime() as unknown as Date;
86
+ signUpResult.user.updatedAt = new Date(signUpResult.user.updatedAt).getTime() as unknown as Date;
87
+ expect(result?.user).toBeDefined();
88
+ expect(result?.user).toStrictEqual(signUpResult.user);
89
+ expect(result?.session).toBeDefined();
90
+ },
91
+ "should not sign in with invalid email": async () => {
92
+ const auth = await getAuth();
93
+ const user = await generate("user");
94
+ const { data, error } = await tryCatch(
95
+ auth.api.signInEmail({
96
+ body: { email: user.email, password: crypto.randomUUID() },
97
+ }),
98
+ );
99
+ expect(data).toBeNull();
100
+ expect(error).toBeDefined();
101
+ },
102
+ "should store and retrieve timestamps correctly across timezones": async () => {
103
+ const originalTZ = process.env.TZ;
104
+ try {
105
+ const auth = await getAuth();
106
+ const user = await generate("user");
107
+ const password = crypto.randomUUID();
108
+ const userSignUp = await auth.api.signUpEmail({
109
+ body: {
110
+ email: user.email,
111
+ password,
112
+ name: user.name,
113
+ image: user.image || "",
114
+ },
115
+ });
116
+ process.env.TZ = "Europe/London";
117
+ const userSignIn = await auth.api.signInEmail({
118
+ body: { email: user.email, password },
119
+ });
120
+ process.env.TZ = "America/Los_Angeles";
121
+ expect(userSignUp.user.createdAt).toStrictEqual(userSignIn.user.createdAt);
122
+ } finally {
123
+ if (originalTZ === undefined) {
124
+ delete process.env.TZ;
125
+ } else {
126
+ process.env.TZ = originalTZ;
127
+ }
128
+ }
129
+ },
130
+ "should sign up with additional fields": async () => {
131
+ await modifyBetterAuthOptions(
132
+ { user: { additionalFields: { dateField: { type: "date" } } } },
133
+ true,
134
+ );
135
+ const auth = await getAuth();
136
+ const user = await generate("user");
137
+ const dateField = new Date();
138
+ const response = await auth.api.signUpEmail({
139
+ body: {
140
+ email: user.email,
141
+ name: user.name,
142
+ password: crypto.randomUUID(),
143
+ //@ts-expect-error - we are testing with additional fields
144
+ dateField: dateField.toISOString(),
145
+ },
146
+ asResponse: true,
147
+ });
148
+ const headers = new Headers();
149
+ setCookieToHeader(headers)({ response });
150
+ const result = await auth.api.getSession({
151
+ headers,
152
+ });
153
+ //@ts-expect-error - we are testing with additional fields
154
+ expect(result?.user.dateField).toStrictEqual(dateField.getTime());
155
+ },
150
156
  });
151
-
152
- /**
153
- * This test suite tests basic authentication flow using the adapter.
154
- */
155
- export const authFlowTestSuite = createTestSuite(
156
- "auth-flow",
157
- {
158
- defaultBetterAuthOptions: AUTH_FLOW_DEFAULT_BETTER_AUTH_OPTIONS,
159
- },
160
- (helpers) => getAuthFlowSuiteTests(helpers),
161
- );
162
-
163
- function recoverProcessTZ() {
164
- const originalTZ = process.env.TZ;
165
- return {
166
- [Symbol.dispose]: () => {
167
- process.env.TZ = originalTZ;
168
- },
169
- };
170
- }