@convex-dev/better-auth 0.10.12 → 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.
Files changed (185) hide show
  1. package/dist/auth-options.d.ts.map +1 -1
  2. package/dist/auth-options.js +0 -2
  3. package/dist/auth-options.js.map +1 -1
  4. package/dist/client/adapter-utils.d.ts +10 -10
  5. package/dist/client/adapter-utils.d.ts.map +1 -1
  6. package/dist/client/adapter-utils.js +41 -32
  7. package/dist/client/adapter-utils.js.map +1 -1
  8. package/dist/client/adapter.d.ts +1 -1
  9. package/dist/client/adapter.d.ts.map +1 -1
  10. package/dist/client/adapter.js +113 -7
  11. package/dist/client/adapter.js.map +1 -1
  12. package/dist/client/create-api.d.ts +8 -7
  13. package/dist/client/create-api.d.ts.map +1 -1
  14. package/dist/client/create-api.js +1 -0
  15. package/dist/client/create-api.js.map +1 -1
  16. package/dist/client/create-client.d.ts +1 -1
  17. package/dist/client/create-client.d.ts.map +1 -1
  18. package/dist/client/create-client.js +8 -7
  19. package/dist/client/create-client.js.map +1 -1
  20. package/dist/client/create-schema.d.ts +0 -1
  21. package/dist/client/create-schema.d.ts.map +1 -1
  22. package/dist/client/create-schema.js +0 -1
  23. package/dist/client/create-schema.js.map +1 -1
  24. package/dist/component/_generated/api.d.ts +12 -0
  25. package/dist/component/_generated/api.d.ts.map +1 -1
  26. package/dist/component/_generated/api.js.map +1 -1
  27. package/dist/component/_generated/component.d.ts +7407 -92
  28. package/dist/component/_generated/component.d.ts.map +1 -1
  29. package/dist/component/adapter.d.ts +8 -7
  30. package/dist/component/adapter.d.ts.map +1 -1
  31. package/dist/component/adapterTest.d.ts +1 -7
  32. package/dist/component/adapterTest.d.ts.map +1 -1
  33. package/dist/component/adapterTest.js +193 -390
  34. package/dist/component/adapterTest.js.map +1 -1
  35. package/dist/component/schema.d.ts +35 -74
  36. package/dist/component/schema.d.ts.map +1 -1
  37. package/dist/component/schema.js +16 -21
  38. package/dist/component/schema.js.map +1 -1
  39. package/dist/component/testProfiles/adapterAdditionalFields.d.ts +131 -0
  40. package/dist/component/testProfiles/adapterAdditionalFields.d.ts.map +1 -0
  41. package/dist/component/testProfiles/adapterAdditionalFields.js +5 -0
  42. package/dist/component/testProfiles/adapterAdditionalFields.js.map +1 -0
  43. package/dist/component/testProfiles/adapterOrganizationJoins.d.ts +131 -0
  44. package/dist/component/testProfiles/adapterOrganizationJoins.d.ts.map +1 -0
  45. package/dist/component/testProfiles/adapterOrganizationJoins.js +5 -0
  46. package/dist/component/testProfiles/adapterOrganizationJoins.js.map +1 -0
  47. package/dist/component/testProfiles/adapterPluginTable.d.ts +131 -0
  48. package/dist/component/testProfiles/adapterPluginTable.d.ts.map +1 -0
  49. package/dist/component/testProfiles/adapterPluginTable.js +5 -0
  50. package/dist/component/testProfiles/adapterPluginTable.js.map +1 -0
  51. package/dist/component/testProfiles/adapterRenameField.d.ts +131 -0
  52. package/dist/component/testProfiles/adapterRenameField.d.ts.map +1 -0
  53. package/dist/component/testProfiles/adapterRenameField.js +5 -0
  54. package/dist/component/testProfiles/adapterRenameField.js.map +1 -0
  55. package/dist/component/testProfiles/adapterRenameUserCustom.d.ts +131 -0
  56. package/dist/component/testProfiles/adapterRenameUserCustom.d.ts.map +1 -0
  57. package/dist/component/testProfiles/adapterRenameUserCustom.js +5 -0
  58. package/dist/component/testProfiles/adapterRenameUserCustom.js.map +1 -0
  59. package/dist/component/testProfiles/adapterRenameUserTable.d.ts +131 -0
  60. package/dist/component/testProfiles/adapterRenameUserTable.d.ts.map +1 -0
  61. package/dist/component/testProfiles/adapterRenameUserTable.js +5 -0
  62. package/dist/component/testProfiles/adapterRenameUserTable.js.map +1 -0
  63. package/dist/component/testProfiles/auth-options.profile-additional-fields.d.ts +3 -0
  64. package/dist/component/testProfiles/auth-options.profile-additional-fields.d.ts.map +1 -0
  65. package/dist/component/testProfiles/auth-options.profile-additional-fields.js +38 -0
  66. package/dist/component/testProfiles/auth-options.profile-additional-fields.js.map +1 -0
  67. package/dist/component/testProfiles/auth-options.profile-plugin-table.d.ts +3 -0
  68. package/dist/component/testProfiles/auth-options.profile-plugin-table.d.ts.map +1 -0
  69. package/dist/component/testProfiles/auth-options.profile-plugin-table.js +92 -0
  70. package/dist/component/testProfiles/auth-options.profile-plugin-table.js.map +1 -0
  71. package/dist/component/testProfiles/auth-options.profile-rename-joins.d.ts +6 -0
  72. package/dist/component/testProfiles/auth-options.profile-rename-joins.d.ts.map +1 -0
  73. package/dist/component/testProfiles/auth-options.profile-rename-joins.js +49 -0
  74. package/dist/component/testProfiles/auth-options.profile-rename-joins.js.map +1 -0
  75. package/dist/component/testProfiles/schema.profile-additional-fields.d.ts +227 -0
  76. package/dist/component/testProfiles/schema.profile-additional-fields.d.ts.map +1 -0
  77. package/dist/component/testProfiles/schema.profile-additional-fields.js +37 -0
  78. package/dist/component/testProfiles/schema.profile-additional-fields.js.map +1 -0
  79. package/dist/component/testProfiles/schema.profile-plugin-table.d.ts +450 -0
  80. package/dist/component/testProfiles/schema.profile-plugin-table.d.ts.map +1 -0
  81. package/dist/component/testProfiles/schema.profile-plugin-table.js +116 -0
  82. package/dist/component/testProfiles/schema.profile-plugin-table.js.map +1 -0
  83. package/dist/nextjs/index.d.ts.map +1 -1
  84. package/dist/nextjs/index.js +1 -0
  85. package/dist/nextjs/index.js.map +1 -1
  86. package/dist/plugins/convex/index.d.ts +131 -12
  87. package/dist/plugins/convex/index.d.ts.map +1 -1
  88. package/dist/plugins/convex/index.js +12 -5
  89. package/dist/plugins/convex/index.js.map +1 -1
  90. package/dist/plugins/cross-domain/client.d.ts +1 -1
  91. package/dist/plugins/cross-domain/index.d.ts +126 -1
  92. package/dist/plugins/cross-domain/index.d.ts.map +1 -1
  93. package/dist/plugins/cross-domain/index.js +11 -16
  94. package/dist/plugins/cross-domain/index.js.map +1 -1
  95. package/dist/react-start/index.d.ts.map +1 -1
  96. package/dist/react-start/index.js +1 -0
  97. package/dist/react-start/index.js.map +1 -1
  98. package/dist/test/adapter-factory/auth-flow.d.ts +42 -0
  99. package/dist/test/adapter-factory/auth-flow.d.ts.map +1 -0
  100. package/dist/test/adapter-factory/auth-flow.js +145 -0
  101. package/dist/test/adapter-factory/auth-flow.js.map +1 -0
  102. package/dist/test/adapter-factory/basic.d.ts +190 -0
  103. package/dist/test/adapter-factory/basic.d.ts.map +1 -0
  104. package/dist/test/adapter-factory/basic.js +2713 -0
  105. package/dist/test/adapter-factory/basic.js.map +1 -0
  106. package/dist/test/adapter-factory/convex-custom.d.ts +18 -0
  107. package/dist/test/adapter-factory/convex-custom.d.ts.map +1 -0
  108. package/dist/test/adapter-factory/convex-custom.js +610 -0
  109. package/dist/test/adapter-factory/convex-custom.js.map +1 -0
  110. package/dist/test/adapter-factory/index.d.ts +11 -0
  111. package/dist/test/adapter-factory/index.d.ts.map +1 -0
  112. package/dist/test/adapter-factory/index.js +11 -0
  113. package/dist/test/adapter-factory/index.js.map +1 -0
  114. package/dist/test/adapter-factory/joins.d.ts +18 -0
  115. package/dist/test/adapter-factory/joins.d.ts.map +1 -0
  116. package/dist/test/adapter-factory/joins.js +22 -0
  117. package/dist/test/adapter-factory/joins.js.map +1 -0
  118. package/dist/test/adapter-factory/number-id.d.ts +18 -0
  119. package/dist/test/adapter-factory/number-id.d.ts.map +1 -0
  120. package/dist/test/adapter-factory/number-id.js +36 -0
  121. package/dist/test/adapter-factory/number-id.js.map +1 -0
  122. package/dist/test/adapter-factory/profile-additional-fields.d.ts +71 -0
  123. package/dist/test/adapter-factory/profile-additional-fields.d.ts.map +1 -0
  124. package/dist/test/adapter-factory/profile-additional-fields.js +44 -0
  125. package/dist/test/adapter-factory/profile-additional-fields.js.map +1 -0
  126. package/dist/test/adapter-factory/profile-plugin-table.d.ts +19 -0
  127. package/dist/test/adapter-factory/profile-plugin-table.d.ts.map +1 -0
  128. package/dist/test/adapter-factory/profile-plugin-table.js +25 -0
  129. package/dist/test/adapter-factory/profile-plugin-table.js.map +1 -0
  130. package/dist/test/adapter-factory/profile-rename-joins.d.ts +73 -0
  131. package/dist/test/adapter-factory/profile-rename-joins.d.ts.map +1 -0
  132. package/dist/test/adapter-factory/profile-rename-joins.js +34 -0
  133. package/dist/test/adapter-factory/profile-rename-joins.js.map +1 -0
  134. package/dist/test/adapter-factory/transactions.d.ts +21 -0
  135. package/dist/test/adapter-factory/transactions.d.ts.map +1 -0
  136. package/dist/test/adapter-factory/transactions.js +28 -0
  137. package/dist/test/adapter-factory/transactions.js.map +1 -0
  138. package/dist/test/adapter-factory/uuid.d.ts +18 -0
  139. package/dist/test/adapter-factory/uuid.d.ts.map +1 -0
  140. package/dist/test/adapter-factory/uuid.js +58 -0
  141. package/dist/test/adapter-factory/uuid.js.map +1 -0
  142. package/dist/utils/index.d.ts +18 -3
  143. package/dist/utils/index.d.ts.map +1 -1
  144. package/dist/utils/index.js.map +1 -1
  145. package/package.json +9 -6
  146. package/src/auth-options.ts +0 -2
  147. package/src/client/adapter-utils.ts +80 -73
  148. package/src/client/adapter.test.ts +2 -74
  149. package/src/client/adapter.ts +142 -7
  150. package/src/client/create-api.ts +1 -0
  151. package/src/client/create-client.ts +14 -6
  152. package/src/client/create-schema.ts +0 -1
  153. package/src/component/_generated/api.ts +12 -0
  154. package/src/component/_generated/component.ts +19454 -215
  155. package/src/component/adapterTest.ts +250 -466
  156. package/src/component/schema.ts +21 -26
  157. package/src/component/testProfiles/adapterAdditionalFields.ts +13 -0
  158. package/src/component/testProfiles/adapterOrganizationJoins.ts +13 -0
  159. package/src/component/testProfiles/adapterPluginTable.ts +13 -0
  160. package/src/component/testProfiles/adapterRenameField.ts +13 -0
  161. package/src/component/testProfiles/adapterRenameUserCustom.ts +13 -0
  162. package/src/component/testProfiles/adapterRenameUserTable.ts +13 -0
  163. package/src/component/testProfiles/auth-options.profile-additional-fields.ts +39 -0
  164. package/src/component/testProfiles/auth-options.profile-plugin-table.ts +93 -0
  165. package/src/component/testProfiles/auth-options.profile-rename-joins.ts +54 -0
  166. package/src/component/testProfiles/schema.profile-additional-fields.ts +39 -0
  167. package/src/component/testProfiles/schema.profile-plugin-table.ts +130 -0
  168. package/src/nextjs/index.ts +1 -0
  169. package/src/plugins/convex/index.test.ts +55 -0
  170. package/src/plugins/convex/index.ts +26 -11
  171. package/src/plugins/cross-domain/index.test.ts +67 -0
  172. package/src/plugins/cross-domain/index.ts +11 -22
  173. package/src/react-start/index.ts +1 -0
  174. package/src/test/adapter-factory/auth-flow.ts +170 -0
  175. package/src/test/adapter-factory/basic.ts +3190 -0
  176. package/src/test/adapter-factory/convex-custom.ts +706 -0
  177. package/src/test/adapter-factory/index.ts +10 -0
  178. package/src/test/adapter-factory/joins.ts +28 -0
  179. package/src/test/adapter-factory/number-id.ts +45 -0
  180. package/src/test/adapter-factory/profile-additional-fields.ts +84 -0
  181. package/src/test/adapter-factory/profile-plugin-table.ts +37 -0
  182. package/src/test/adapter-factory/profile-rename-joins.ts +67 -0
  183. package/src/test/adapter-factory/transactions.ts +38 -0
  184. package/src/test/adapter-factory/uuid.ts +67 -0
  185. package/src/utils/index.ts +25 -3
@@ -1,6 +1,12 @@
1
- // This file is auto-generated. Do not edit this file manually.
2
- // To regenerate the schema, run:
3
- // `npx @better-auth/cli generate --output src/component/schema.ts -y`
1
+ /**
2
+ * This file is auto-generated. Do not edit this file manually.
3
+ * To regenerate the schema, run:
4
+ * `npx @better-auth/cli generate --output src/component/schema.ts -y`
5
+ *
6
+ * To customize the schema, generate to an alternate file and import
7
+ * the table definitions to your schema file. See
8
+ * https://labs.convex.dev/better-auth/features/local-install#adding-custom-indexes.
9
+ */
4
10
 
5
11
  import { defineSchema, defineTable } from "convex/server";
6
12
  import { v } from "convex/values";
@@ -21,7 +27,7 @@ export const tables = {
21
27
  phoneNumberVerified: v.optional(v.union(v.null(), v.boolean())),
22
28
  userId: v.optional(v.union(v.null(), v.string())),
23
29
  })
24
- .index("email_name", ["email", "name"])
30
+ .index("email_name", ["email","name"])
25
31
  .index("name", ["name"])
26
32
  .index("userId", ["userId"])
27
33
  .index("username", ["username"])
@@ -36,7 +42,7 @@ export const tables = {
36
42
  userId: v.string(),
37
43
  })
38
44
  .index("expiresAt", ["expiresAt"])
39
- .index("expiresAt_userId", ["expiresAt", "userId"])
45
+ .index("expiresAt_userId", ["expiresAt","userId"])
40
46
  .index("token", ["token"])
41
47
  .index("userId", ["userId"]),
42
48
  account: defineTable({
@@ -54,8 +60,8 @@ export const tables = {
54
60
  updatedAt: v.number(),
55
61
  })
56
62
  .index("accountId", ["accountId"])
57
- .index("accountId_providerId", ["accountId", "providerId"])
58
- .index("providerId_userId", ["providerId", "userId"])
63
+ .index("accountId_providerId", ["accountId","providerId"])
64
+ .index("providerId_userId", ["providerId","userId"])
59
65
  .index("userId", ["userId"]),
60
66
  verification: defineTable({
61
67
  identifier: v.string(),
@@ -70,20 +76,7 @@ export const tables = {
70
76
  secret: v.string(),
71
77
  backupCodes: v.string(),
72
78
  userId: v.string(),
73
- }).index("userId", ["userId"]),
74
- passkey: defineTable({
75
- name: v.optional(v.union(v.null(), v.string())),
76
- publicKey: v.string(),
77
- userId: v.string(),
78
- credentialID: v.string(),
79
- counter: v.number(),
80
- deviceType: v.string(),
81
- backedUp: v.boolean(),
82
- transports: v.optional(v.union(v.null(), v.string())),
83
- createdAt: v.optional(v.union(v.null(), v.number())),
84
- aaguid: v.optional(v.union(v.null(), v.string())),
85
79
  })
86
- .index("credentialID", ["credentialID"])
87
80
  .index("userId", ["userId"]),
88
81
  oauthApplication: defineTable({
89
82
  name: v.optional(v.union(v.null(), v.string())),
@@ -91,7 +84,7 @@ export const tables = {
91
84
  metadata: v.optional(v.union(v.null(), v.string())),
92
85
  clientId: v.optional(v.union(v.null(), v.string())),
93
86
  clientSecret: v.optional(v.union(v.null(), v.string())),
94
- redirectURLs: v.optional(v.union(v.null(), v.string())),
87
+ redirectUrls: v.optional(v.union(v.null(), v.string())),
95
88
  type: v.optional(v.union(v.null(), v.string())),
96
89
  disabled: v.optional(v.union(v.null(), v.boolean())),
97
90
  userId: v.optional(v.union(v.null(), v.string())),
@@ -123,18 +116,20 @@ export const tables = {
123
116
  updatedAt: v.optional(v.union(v.null(), v.number())),
124
117
  consentGiven: v.optional(v.union(v.null(), v.boolean())),
125
118
  })
126
- .index("clientId_userId", ["clientId", "userId"])
119
+ .index("clientId_userId", ["clientId","userId"])
127
120
  .index("userId", ["userId"]),
128
121
  jwks: defineTable({
129
122
  publicKey: v.string(),
130
123
  privateKey: v.string(),
131
124
  createdAt: v.number(),
125
+ expiresAt: v.optional(v.union(v.null(), v.number())),
132
126
  }),
133
127
  rateLimit: defineTable({
134
- key: v.optional(v.union(v.null(), v.string())),
135
- count: v.optional(v.union(v.null(), v.number())),
136
- lastRequest: v.optional(v.union(v.null(), v.number())),
137
- }).index("key", ["key"]),
128
+ key: v.string(),
129
+ count: v.number(),
130
+ lastRequest: v.number(),
131
+ })
132
+ .index("key", ["key"]),
138
133
  };
139
134
 
140
135
  const schema = defineSchema(tables);
@@ -0,0 +1,13 @@
1
+ import { createApi } from "../../client/index.js";
2
+ import { additionalFieldsProfileOptions } from "./auth-options.profile-additional-fields.js";
3
+ import schema from "./schema.profile-additional-fields.js";
4
+
5
+ export const {
6
+ create,
7
+ findOne,
8
+ findMany,
9
+ updateOne,
10
+ updateMany,
11
+ deleteOne,
12
+ deleteMany,
13
+ } = createApi(schema, () => additionalFieldsProfileOptions);
@@ -0,0 +1,13 @@
1
+ import { createApi } from "../../client/index.js";
2
+ import { organizationJoinsProfileOptions } from "./auth-options.profile-rename-joins.js";
3
+ import schema from "./schema.profile-plugin-table.js";
4
+
5
+ export const {
6
+ create,
7
+ findOne,
8
+ findMany,
9
+ updateOne,
10
+ updateMany,
11
+ deleteOne,
12
+ deleteMany,
13
+ } = createApi(schema, () => organizationJoinsProfileOptions);
@@ -0,0 +1,13 @@
1
+ import { createApi } from "../../client/index.js";
2
+ import { pluginTableProfileOptions } from "./auth-options.profile-plugin-table.js";
3
+ import schema from "./schema.profile-plugin-table.js";
4
+
5
+ export const {
6
+ create,
7
+ findOne,
8
+ findMany,
9
+ updateOne,
10
+ updateMany,
11
+ deleteOne,
12
+ deleteMany,
13
+ } = createApi(schema, () => pluginTableProfileOptions);
@@ -0,0 +1,13 @@
1
+ import { createApi } from "../../client/index.js";
2
+ import { renameFieldProfileOptions } from "./auth-options.profile-rename-joins.js";
3
+ import schema from "./schema.profile-plugin-table.js";
4
+
5
+ export const {
6
+ create,
7
+ findOne,
8
+ findMany,
9
+ updateOne,
10
+ updateMany,
11
+ deleteOne,
12
+ deleteMany,
13
+ } = createApi(schema, () => renameFieldProfileOptions);
@@ -0,0 +1,13 @@
1
+ import { createApi } from "../../client/index.js";
2
+ import { renameModelUserCustomProfileOptions } from "./auth-options.profile-rename-joins.js";
3
+ import schema from "./schema.profile-plugin-table.js";
4
+
5
+ export const {
6
+ create,
7
+ findOne,
8
+ findMany,
9
+ updateOne,
10
+ updateMany,
11
+ deleteOne,
12
+ deleteMany,
13
+ } = createApi(schema, () => renameModelUserCustomProfileOptions);
@@ -0,0 +1,13 @@
1
+ import { createApi } from "../../client/index.js";
2
+ import { renameModelUserTableProfileOptions } from "./auth-options.profile-rename-joins.js";
3
+ import schema from "./schema.profile-plugin-table.js";
4
+
5
+ export const {
6
+ create,
7
+ findOne,
8
+ findMany,
9
+ updateOne,
10
+ updateMany,
11
+ deleteOne,
12
+ deleteMany,
13
+ } = createApi(schema, () => renameModelUserTableProfileOptions);
@@ -0,0 +1,39 @@
1
+ import type { BetterAuthOptions } from "better-auth/minimal";
2
+ import { options } from "../../auth-options.js";
3
+
4
+ // Test-only options used to build a schema/validator profile that supports
5
+ // additional-fields coverage in adapter tests.
6
+ export const additionalFieldsProfileOptions = {
7
+ ...options,
8
+ user: {
9
+ ...options.user,
10
+ additionalFields: {
11
+ ...options.user?.additionalFields,
12
+ customField: {
13
+ type: "string",
14
+ required: false,
15
+ input: false,
16
+ defaultValue: "default-value",
17
+ },
18
+ numericField: {
19
+ type: "number",
20
+ required: false,
21
+ defaultValue: 0,
22
+ },
23
+ testField: {
24
+ type: "string",
25
+ required: false,
26
+ defaultValue: "test-value",
27
+ },
28
+ cbDefaultValueField: {
29
+ type: "string",
30
+ required: false,
31
+ defaultValue: () => "advanced-test-value",
32
+ },
33
+ dateField: {
34
+ type: "date",
35
+ required: false,
36
+ },
37
+ },
38
+ },
39
+ } as BetterAuthOptions;
@@ -0,0 +1,93 @@
1
+ import type { BetterAuthOptions } from "better-auth/minimal";
2
+ import { options } from "../../auth-options.js";
3
+
4
+ // Test-only options used to provide static schema coverage for tests that
5
+ // otherwise mutate plugin tables and user additional fields at runtime.
6
+ export const pluginTableProfileOptions = {
7
+ ...options,
8
+ user: {
9
+ ...options.user,
10
+ additionalFields: {
11
+ ...options.user?.additionalFields,
12
+ testField: {
13
+ type: "string",
14
+ required: false,
15
+ defaultValue: "test-value",
16
+ },
17
+ cbDefaultValueField: {
18
+ type: "string",
19
+ required: false,
20
+ defaultValue: () => "advanced-test-value",
21
+ },
22
+ customField: {
23
+ type: "string",
24
+ required: false,
25
+ input: false,
26
+ defaultValue: "default-value",
27
+ },
28
+ numericField: {
29
+ type: "number",
30
+ required: false,
31
+ defaultValue: 0,
32
+ },
33
+ dateField: {
34
+ type: "date",
35
+ required: false,
36
+ },
37
+ },
38
+ },
39
+ plugins: [
40
+ ...(options.plugins ?? []),
41
+ {
42
+ id: "one-to-one-test",
43
+ schema: {
44
+ oneToOneTable: {
45
+ fields: {
46
+ oneToOne: {
47
+ type: "string",
48
+ required: true,
49
+ references: { field: "id", model: "user" },
50
+ unique: true,
51
+ },
52
+ },
53
+ },
54
+ },
55
+ },
56
+ {
57
+ id: "plugin-table-test-model",
58
+ schema: {
59
+ testModel: {
60
+ fields: {
61
+ nullableReference: {
62
+ type: "string",
63
+ references: { field: "id", model: "user" },
64
+ required: false,
65
+ },
66
+ testField: {
67
+ type: "string",
68
+ required: false,
69
+ defaultValue: "test-value",
70
+ },
71
+ cbDefaultValueField: {
72
+ type: "string",
73
+ required: false,
74
+ defaultValue: () => "advanced-test-value",
75
+ },
76
+ stringArray: {
77
+ type: "string[]",
78
+ required: false,
79
+ },
80
+ numberArray: {
81
+ type: "number[]",
82
+ required: false,
83
+ },
84
+ json: {
85
+ type: "json",
86
+ required: false,
87
+ },
88
+ },
89
+ },
90
+ },
91
+ },
92
+ ],
93
+ } as BetterAuthOptions;
@@ -0,0 +1,54 @@
1
+ import type { BetterAuthOptions } from "better-auth/minimal";
2
+ import { organization } from "better-auth/plugins";
3
+ import { options } from "../../auth-options.js";
4
+
5
+ const renamedOneToOnePlugin = {
6
+ id: "one-to-one-test",
7
+ schema: {
8
+ oneToOneTable: {
9
+ modelName: "one_to_one_table",
10
+ fields: {
11
+ oneToOne: {
12
+ type: "string",
13
+ required: true,
14
+ references: { field: "email", model: "user" },
15
+ unique: true,
16
+ fieldName: "one_to_one",
17
+ },
18
+ },
19
+ },
20
+ },
21
+ };
22
+
23
+ export const renameFieldProfileOptions = {
24
+ ...options,
25
+ user: {
26
+ ...options.user,
27
+ fields: {
28
+ ...options.user?.fields,
29
+ email: "email_address",
30
+ },
31
+ },
32
+ plugins: [...(options.plugins ?? []), renamedOneToOnePlugin],
33
+ } as BetterAuthOptions;
34
+
35
+ export const renameModelUserCustomProfileOptions = {
36
+ ...options,
37
+ user: {
38
+ ...options.user,
39
+ modelName: "user_custom",
40
+ },
41
+ } as BetterAuthOptions;
42
+
43
+ export const renameModelUserTableProfileOptions = {
44
+ ...options,
45
+ user: {
46
+ ...options.user,
47
+ modelName: "user_table",
48
+ },
49
+ } as BetterAuthOptions;
50
+
51
+ export const organizationJoinsProfileOptions = {
52
+ ...options,
53
+ plugins: [...(options.plugins ?? []), organization({ teams: { enabled: true } })],
54
+ } as BetterAuthOptions;
@@ -0,0 +1,39 @@
1
+ import { defineSchema, defineTable } from "convex/server";
2
+ import { v } from "convex/values";
3
+ import { tables as baseTables } from "../schema.js";
4
+
5
+ const userTableWithAdditionalFields = defineTable({
6
+ name: v.string(),
7
+ email: v.string(),
8
+ emailVerified: v.boolean(),
9
+ image: v.optional(v.union(v.null(), v.string())),
10
+ createdAt: v.number(),
11
+ updatedAt: v.number(),
12
+ twoFactorEnabled: v.optional(v.union(v.null(), v.boolean())),
13
+ isAnonymous: v.optional(v.union(v.null(), v.boolean())),
14
+ username: v.optional(v.union(v.null(), v.string())),
15
+ displayUsername: v.optional(v.union(v.null(), v.string())),
16
+ phoneNumber: v.optional(v.union(v.null(), v.string())),
17
+ phoneNumberVerified: v.optional(v.union(v.null(), v.boolean())),
18
+ userId: v.optional(v.union(v.null(), v.string())),
19
+ customField: v.optional(v.union(v.null(), v.string())),
20
+ numericField: v.optional(v.union(v.null(), v.number())),
21
+ testField: v.optional(v.union(v.null(), v.string())),
22
+ cbDefaultValueField: v.optional(v.union(v.null(), v.string())),
23
+ dateField: v.optional(v.union(v.null(), v.number())),
24
+ })
25
+ .index("email_name", ["email", "name"])
26
+ .index("name", ["name"])
27
+ .index("userId", ["userId"])
28
+ .index("username", ["username"])
29
+ .index("phoneNumber", ["phoneNumber"])
30
+ .index("customField", ["customField"])
31
+ .index("numericField", ["numericField"])
32
+ .index("dateField", ["dateField"]);
33
+
34
+ const schema = defineSchema({
35
+ ...baseTables,
36
+ user: userTableWithAdditionalFields,
37
+ });
38
+
39
+ export default schema;
@@ -0,0 +1,130 @@
1
+ import { defineSchema, defineTable } from "convex/server";
2
+ import { v } from "convex/values";
3
+ import { tables as baseTables } from "../schema.js";
4
+
5
+ const makeUserTable = () =>
6
+ defineTable({
7
+ name: v.string(),
8
+ email: v.optional(v.union(v.null(), v.string())),
9
+ email_address: v.optional(v.union(v.null(), v.string())),
10
+ emailVerified: v.boolean(),
11
+ image: v.optional(v.union(v.null(), v.string())),
12
+ createdAt: v.number(),
13
+ updatedAt: v.number(),
14
+ twoFactorEnabled: v.optional(v.union(v.null(), v.boolean())),
15
+ isAnonymous: v.optional(v.union(v.null(), v.boolean())),
16
+ username: v.optional(v.union(v.null(), v.string())),
17
+ displayUsername: v.optional(v.union(v.null(), v.string())),
18
+ phoneNumber: v.optional(v.union(v.null(), v.string())),
19
+ phoneNumberVerified: v.optional(v.union(v.null(), v.boolean())),
20
+ userId: v.optional(v.union(v.null(), v.string())),
21
+ testField: v.optional(v.union(v.null(), v.string())),
22
+ cbDefaultValueField: v.optional(v.union(v.null(), v.string())),
23
+ customField: v.optional(v.union(v.null(), v.string())),
24
+ numericField: v.optional(v.union(v.null(), v.number())),
25
+ dateField: v.optional(v.union(v.null(), v.number())),
26
+ })
27
+ .index("email_name", ["email", "name"])
28
+ .index("email_address_name", ["email_address", "name"])
29
+ .index("name", ["name"])
30
+ .index("userId", ["userId"])
31
+ .index("username", ["username"])
32
+ .index("phoneNumber", ["phoneNumber"])
33
+ .index("customField", ["customField"])
34
+ .index("numericField", ["numericField"])
35
+ .index("dateField", ["dateField"]);
36
+
37
+ const userTableWithProfileFields = makeUserTable();
38
+
39
+ const userCustomTable = makeUserTable();
40
+
41
+ const userTableRenamed = makeUserTable();
42
+
43
+ const oneToOneTable = defineTable({
44
+ oneToOne: v.string(),
45
+ }).index("oneToOne", ["oneToOne"]);
46
+
47
+ const oneToOneTableRenamed = defineTable({
48
+ oneToOne: v.optional(v.union(v.null(), v.string())),
49
+ one_to_one: v.optional(v.union(v.null(), v.string())),
50
+ })
51
+ .index("oneToOne", ["oneToOne"])
52
+ .index("one_to_one", ["one_to_one"]);
53
+
54
+ const testModelTable = defineTable({
55
+ nullableReference: v.optional(v.union(v.null(), v.string())),
56
+ testField: v.optional(v.union(v.null(), v.string())),
57
+ cbDefaultValueField: v.optional(v.union(v.null(), v.string())),
58
+ stringArray: v.optional(v.union(v.null(), v.array(v.string()))),
59
+ numberArray: v.optional(v.union(v.null(), v.array(v.number()))),
60
+ json: v.optional(v.any()),
61
+ }).index("nullableReference", ["nullableReference"]);
62
+
63
+ const organizationTable = defineTable({
64
+ name: v.string(),
65
+ slug: v.string(),
66
+ logo: v.optional(v.union(v.null(), v.string())),
67
+ metadata: v.optional(v.union(v.null(), v.string())),
68
+ createdAt: v.number(),
69
+ updatedAt: v.optional(v.union(v.null(), v.number())),
70
+ })
71
+ .index("slug", ["slug"])
72
+ .index("name", ["name"]);
73
+
74
+ const memberTable = defineTable({
75
+ organizationId: v.string(),
76
+ userId: v.string(),
77
+ role: v.string(),
78
+ createdAt: v.number(),
79
+ updatedAt: v.optional(v.union(v.null(), v.number())),
80
+ })
81
+ .index("organizationId", ["organizationId"])
82
+ .index("userId", ["userId"]);
83
+
84
+ const teamTable = defineTable({
85
+ name: v.string(),
86
+ organizationId: v.string(),
87
+ createdAt: v.number(),
88
+ updatedAt: v.optional(v.union(v.null(), v.number())),
89
+ })
90
+ .index("organizationId", ["organizationId"])
91
+ .index("name", ["name"]);
92
+
93
+ const teamMemberTable = defineTable({
94
+ teamId: v.string(),
95
+ userId: v.string(),
96
+ createdAt: v.optional(v.union(v.null(), v.number())),
97
+ })
98
+ .index("teamId", ["teamId"])
99
+ .index("userId", ["userId"]);
100
+
101
+ const invitationTable = defineTable({
102
+ email: v.optional(v.union(v.null(), v.string())),
103
+ role: v.optional(v.union(v.null(), v.string())),
104
+ status: v.optional(v.union(v.null(), v.string())),
105
+ organizationId: v.optional(v.union(v.null(), v.string())),
106
+ teamId: v.optional(v.union(v.null(), v.string())),
107
+ inviterId: v.optional(v.union(v.null(), v.string())),
108
+ expiresAt: v.optional(v.union(v.null(), v.number())),
109
+ createdAt: v.optional(v.union(v.null(), v.number())),
110
+ updatedAt: v.optional(v.union(v.null(), v.number())),
111
+ })
112
+ .index("organizationId", ["organizationId"])
113
+ .index("email", ["email"]);
114
+
115
+ const schema = defineSchema({
116
+ ...baseTables,
117
+ user: userTableWithProfileFields,
118
+ user_custom: userCustomTable,
119
+ user_table: userTableRenamed,
120
+ oneToOneTable,
121
+ one_to_one_table: oneToOneTableRenamed,
122
+ testModel: testModelTable,
123
+ organization: organizationTable,
124
+ member: memberTable,
125
+ team: teamTable,
126
+ teamMember: teamMemberTable,
127
+ invitation: invitationTable,
128
+ });
129
+
130
+ export default schema;
@@ -77,6 +77,7 @@ export const convexBetterAuthNextJs = (
77
77
  const mutableHeaders = new Headers(headers);
78
78
  mutableHeaders.delete("content-length");
79
79
  mutableHeaders.delete("transfer-encoding");
80
+ mutableHeaders.set("accept-encoding", "identity");
80
81
  return getToken(siteUrl, mutableHeaders, { ...opts, forceRefresh });
81
82
  }
82
83
  );
@@ -0,0 +1,55 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import type { AuthConfig } from "convex/server";
3
+ import { convex } from "./index.js";
4
+
5
+ const authConfig = {
6
+ providers: [{ applicationID: "convex", domain: "https://example.com" }],
7
+ } satisfies AuthConfig;
8
+
9
+ const getJwtSetCookieMatcher = () => {
10
+ const plugin = convex({ authConfig });
11
+ const afterHooks = plugin.hooks?.after ?? [];
12
+ const matcher = afterHooks.find((hook) => {
13
+ return (
14
+ hook.matcher({
15
+ path: "/sign-in/email",
16
+ context: { session: { id: "s1" } },
17
+ } as unknown as Parameters<typeof hook.matcher>[0]) &&
18
+ !hook.matcher({
19
+ path: "/sign-out",
20
+ context: { session: null },
21
+ } as unknown as Parameters<typeof hook.matcher>[0])
22
+ );
23
+ })?.matcher;
24
+ if (!matcher) {
25
+ throw new Error("Failed to find Convex JWT set-cookie after hook matcher");
26
+ }
27
+ return matcher;
28
+ };
29
+
30
+ describe("convex plugin JWT cookie refresh matcher", () => {
31
+ it("matches update-session", () => {
32
+ const matcher = getJwtSetCookieMatcher();
33
+ type MatcherContext = Parameters<typeof matcher>[0];
34
+ const ctx = {
35
+ path: "/update-session",
36
+ context: { session: { id: "s1" } },
37
+ };
38
+ expect(matcher(ctx as unknown as MatcherContext)).toBe(true);
39
+ });
40
+
41
+ it("matches get-session only when a session exists", () => {
42
+ const matcher = getJwtSetCookieMatcher();
43
+ type MatcherContext = Parameters<typeof matcher>[0];
44
+ const withSessionCtx = {
45
+ path: "/get-session",
46
+ context: { session: { id: "s1" } },
47
+ };
48
+ const withoutSessionCtx = {
49
+ path: "/get-session",
50
+ context: { session: null },
51
+ };
52
+ expect(matcher(withSessionCtx as unknown as MatcherContext)).toBe(true);
53
+ expect(matcher(withoutSessionCtx as unknown as MatcherContext)).toBe(false);
54
+ });
55
+ });