@convex-dev/better-auth 0.7.11 → 0.7.12

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 (46) hide show
  1. package/README.md +4 -3
  2. package/dist/commonjs/client/index.d.ts +313 -280
  3. package/dist/commonjs/client/index.d.ts.map +1 -1
  4. package/dist/commonjs/client/index.js +4 -5
  5. package/dist/commonjs/client/index.js.map +1 -1
  6. package/dist/commonjs/component/lib.d.ts +113 -97
  7. package/dist/commonjs/component/lib.d.ts.map +1 -1
  8. package/dist/commonjs/component/lib.js +31 -18
  9. package/dist/commonjs/component/lib.js.map +1 -1
  10. package/dist/commonjs/component/schema.d.ts +235 -199
  11. package/dist/commonjs/component/schema.d.ts.map +1 -1
  12. package/dist/commonjs/component/schema.js +125 -102
  13. package/dist/commonjs/component/schema.js.map +1 -1
  14. package/dist/commonjs/component/util.d.ts +491 -404
  15. package/dist/commonjs/component/util.d.ts.map +1 -1
  16. package/dist/commonjs/nextjs/index.d.ts.map +1 -1
  17. package/dist/commonjs/nextjs/index.js +18 -2
  18. package/dist/commonjs/nextjs/index.js.map +1 -1
  19. package/dist/commonjs/plugins/convex/index.d.ts +9 -9
  20. package/dist/commonjs/plugins/convex/index.d.ts.map +1 -1
  21. package/dist/commonjs/react-start/index.d.ts +6 -6
  22. package/dist/esm/client/index.d.ts +313 -280
  23. package/dist/esm/client/index.d.ts.map +1 -1
  24. package/dist/esm/client/index.js +4 -5
  25. package/dist/esm/client/index.js.map +1 -1
  26. package/dist/esm/component/lib.d.ts +113 -97
  27. package/dist/esm/component/lib.d.ts.map +1 -1
  28. package/dist/esm/component/lib.js +31 -18
  29. package/dist/esm/component/lib.js.map +1 -1
  30. package/dist/esm/component/schema.d.ts +235 -199
  31. package/dist/esm/component/schema.d.ts.map +1 -1
  32. package/dist/esm/component/schema.js +125 -102
  33. package/dist/esm/component/schema.js.map +1 -1
  34. package/dist/esm/component/util.d.ts +491 -404
  35. package/dist/esm/component/util.d.ts.map +1 -1
  36. package/dist/esm/nextjs/index.d.ts.map +1 -1
  37. package/dist/esm/nextjs/index.js +18 -2
  38. package/dist/esm/nextjs/index.js.map +1 -1
  39. package/dist/esm/plugins/convex/index.d.ts +9 -9
  40. package/dist/esm/plugins/convex/index.d.ts.map +1 -1
  41. package/dist/esm/react-start/index.d.ts +6 -6
  42. package/package.json +5 -5
  43. package/src/client/index.ts +4 -5
  44. package/src/component/lib.ts +42 -27
  45. package/src/component/schema.ts +127 -102
  46. package/src/nextjs/index.ts +23 -2
@@ -1 +1 @@
1
- {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/component/util.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gMAC2tY,eAAgB,qEAAqE,CAAC,mJAA0H,aAAc,+MAAuL,eAAe;;mFAAkV,GAAG,gDAAwB,WAAW,2BAA0B,WAAY;;;CAD5ga,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/nextjs/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAGjD,eAAO,MAAM,QAAQ,GACnB,YAAY,CAAC,GAAG,EAAE,gBAAgB,CAAC,GAAG,CAAC,KAAK,UAAU,CAAC,OAAO,UAAU,CAAC,gCAS1E,CAAC;AAeF,eAAO,MAAM,aAAa,GAAI,OAAO;IAAE,aAAa,CAAC,EAAE,MAAM,CAAA;CAAE;mBAC9C,OAAO;oBACN,OAAO;CACvB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/nextjs/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAGjD,eAAO,MAAM,QAAQ,GACnB,YAAY,CAAC,GAAG,EAAE,gBAAgB,CAAC,GAAG,CAAC,KAAK,UAAU,CAAC,OAAO,UAAU,CAAC,gCA8B1E,CAAC;AAeF,eAAO,MAAM,aAAa,GAAI,OAAO;IAAE,aAAa,CAAC,EAAE,MAAM,CAAA;CAAE;mBAC9C,OAAO;oBACN,OAAO;CACvB,CAAC"}
@@ -6,8 +6,24 @@ export const getToken = async (createAuth) => {
6
6
  const auth = createAuth({});
7
7
  const createCookie = createCookieGetter(auth.options);
8
8
  const cookie = createCookie(JWT_COOKIE_NAME);
9
- const token = cookieStore.get(cookie.name);
10
- return token?.value;
9
+ const tokenCookie = cookieStore.get(cookie.name);
10
+ // Warn if there's a secure cookie mismatch between Convex and Next.js
11
+ if (!tokenCookie?.value) {
12
+ const isSecure = cookie.name.startsWith("__Secure-");
13
+ const insecureCookieName = cookie.name.replace("__Secure-", "");
14
+ const insecureCookie = cookieStore.get(insecureCookieName);
15
+ const secureCookieName = isSecure
16
+ ? cookie.name
17
+ : `__Secure-${insecureCookieName}`;
18
+ const secureCookie = cookieStore.get(secureCookieName);
19
+ if (isSecure && insecureCookie) {
20
+ console.warn(`Looking for secure cookie ${cookie.name} but found insecure cookie ${insecureCookie.name}`);
21
+ }
22
+ if (!isSecure && secureCookie) {
23
+ console.warn(`Looking for insecure cookie ${cookie.name} but found secure cookie ${secureCookie.name}`);
24
+ }
25
+ }
26
+ return tokenCookie?.value;
11
27
  };
12
28
  const handler = (request, opts) => {
13
29
  const requestUrl = new URL(request.url);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/nextjs/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,CAAC,MAAM,QAAQ,GAAG,KAAK,EAC3B,UAAyE,EACzE,EAAE;IACF,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC,CAAC;IACjD,MAAM,WAAW,GAAG,MAAM,OAAO,EAAE,CAAC;IACpC,MAAM,IAAI,GAAG,UAAU,CAAC,EAAS,CAAC,CAAC;IACnC,MAAM,YAAY,GAAG,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACtD,MAAM,MAAM,GAAG,YAAY,CAAC,eAAe,CAAC,CAAC;IAC7C,MAAM,KAAK,GAAG,WAAW,CAAC,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EAAE,CAC1F,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO,WAAW,EAAE,KAAK,CAAC;AAC5B,CAAC,CAAC;AAEF,MAAM,OAAO,GAAG,CAAC,OAAgB,EAAE,IAAiC,EAAE,EAAE;IACtE,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACxC,MAAM,aAAa,GACjB,IAAI,EAAE,aAAa,IAAI,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC;IACjE,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC5D,CAAC;IACD,MAAM,OAAO,GAAG,GAAG,aAAa,GAAG,UAAU,CAAC,QAAQ,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC;IAC7E,MAAM,UAAU,GAAG,IAAI,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACjD,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,kBAAkB,CAAC,CAAC;IAC9D,OAAO,KAAK,CAAC,UAAU,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC;AAC3E,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAAiC,EAAE,EAAE,CAAC,CAAC;IACnE,GAAG,EAAE,CAAC,OAAgB,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC;IACjD,IAAI,EAAE,CAAC,OAAgB,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC;CACnD,CAAC,CAAC"}
@@ -57,9 +57,9 @@ export declare const convex: <O extends BetterAuthOptions>(opts?: {
57
57
  response: {
58
58
  user: Omit<import("better-auth").UnionToIntersection<import("better-auth").StripEmptyObjects<{
59
59
  id: string;
60
- name: string;
61
- emailVerified: boolean;
62
60
  email: string;
61
+ emailVerified: boolean;
62
+ name: string;
63
63
  createdAt: Date;
64
64
  updatedAt: Date;
65
65
  image?: string | null | undefined;
@@ -70,11 +70,11 @@ export declare const convex: <O extends BetterAuthOptions>(opts?: {
70
70
  };
71
71
  session: import("better-auth").UnionToIntersection<import("better-auth").StripEmptyObjects<{
72
72
  id: string;
73
- token: string;
74
73
  userId: string;
75
74
  expiresAt: Date;
76
75
  createdAt: Date;
77
76
  updatedAt: Date;
77
+ token: string;
78
78
  ipAddress?: string | null | undefined;
79
79
  userAgent?: string | null | undefined;
80
80
  } & (O extends BetterAuthOptions ? import("better-auth").AdditionalSessionFieldsOutput<O> : O extends import("better-auth").Auth ? import("better-auth").AdditionalSessionFieldsOutput<O["options"]> : {})>> & {
@@ -84,9 +84,9 @@ export declare const convex: <O extends BetterAuthOptions>(opts?: {
84
84
  } : {
85
85
  user: Omit<import("better-auth").UnionToIntersection<import("better-auth").StripEmptyObjects<{
86
86
  id: string;
87
- name: string;
88
- emailVerified: boolean;
89
87
  email: string;
88
+ emailVerified: boolean;
89
+ name: string;
90
90
  createdAt: Date;
91
91
  updatedAt: Date;
92
92
  image?: string | null | undefined;
@@ -97,11 +97,11 @@ export declare const convex: <O extends BetterAuthOptions>(opts?: {
97
97
  };
98
98
  session: import("better-auth").UnionToIntersection<import("better-auth").StripEmptyObjects<{
99
99
  id: string;
100
- token: string;
101
100
  userId: string;
102
101
  expiresAt: Date;
103
102
  createdAt: Date;
104
103
  updatedAt: Date;
104
+ token: string;
105
105
  ipAddress?: string | null | undefined;
106
106
  userAgent?: string | null | undefined;
107
107
  } & (O extends BetterAuthOptions ? import("better-auth").AdditionalSessionFieldsOutput<O> : O extends import("better-auth").Auth ? import("better-auth").AdditionalSessionFieldsOutput<O["options"]> : {})>> & {
@@ -328,19 +328,19 @@ export declare const convex: <O extends BetterAuthOptions>(opts?: {
328
328
  session: {
329
329
  session: Record<string, any> & {
330
330
  id: string;
331
- token: string;
332
331
  userId: string;
333
332
  expiresAt: Date;
334
333
  createdAt: Date;
335
334
  updatedAt: Date;
335
+ token: string;
336
336
  ipAddress?: string | null | undefined;
337
337
  userAgent?: string | null | undefined;
338
338
  };
339
339
  user: Record<string, any> & {
340
340
  id: string;
341
- name: string;
342
- emailVerified: boolean;
343
341
  email: string;
342
+ emailVerified: boolean;
343
+ name: string;
344
344
  createdAt: Date;
345
345
  updatedAt: Date;
346
346
  image?: string | null | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/convex/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,eAAe,eAAe,CAAC;AAE5C,eAAO,MAAM,MAAM,GAAI,CAAC,SAAS,iBAAiB,EAChD,OAAM;IACJ,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,4BAA4B,CAAC,EAAE,OAAO,CAAC;IACvC,OAAO,CAAC,EAAE,CAAC,CAAC;CACR;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gCAaM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;4BAAN,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qCA0V+m4F,CAAC;qCAAkD,CAAC;;;;;;;;;iCAA0Q,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CADj84F,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/convex/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,eAAe,eAAe,CAAC;AAE5C,eAAO,MAAM,MAAM,GAAI,CAAC,SAAS,iBAAiB,EAChD,OAAM;IACJ,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,4BAA4B,CAAC,EAAE,OAAO,CAAC;IACvC,OAAO,CAAC,EAAE,CAAC,CAAC;CACR;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gCAaM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;4BAAN,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qCA0V8jtF,CAAC;qCAAkD,CAAC;;;;;;;;;iCAA0Q,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CADh5tF,CAAC"}
@@ -19,22 +19,22 @@ export declare const reactStartHelpers: (createAuth: (ctx: GenericActionCtx<any>
19
19
  session: {
20
20
  session: {
21
21
  id: string;
22
- token: string;
23
22
  userId: string;
24
23
  expiresAt: Date;
25
24
  createdAt: Date;
26
25
  updatedAt: Date;
27
- ipAddress?: string | null | undefined | undefined;
28
- userAgent?: string | null | undefined | undefined;
26
+ token: string;
27
+ ipAddress?: string | null | undefined;
28
+ userAgent?: string | null | undefined;
29
29
  };
30
30
  user: {
31
31
  id: string;
32
- name: string;
33
- emailVerified: boolean;
34
32
  email: string;
33
+ emailVerified: boolean;
34
+ name: string;
35
35
  createdAt: Date;
36
36
  updatedAt: Date;
37
- image?: string | null | undefined | undefined;
37
+ image?: string | null | undefined;
38
38
  };
39
39
  } | null;
40
40
  }>;
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.7.11",
9
+ "version": "0.7.12",
10
10
  "license": "Apache-2.0",
11
11
  "keywords": [
12
12
  "convex",
@@ -18,7 +18,7 @@
18
18
  ],
19
19
  "type": "module",
20
20
  "scripts": {
21
- "build": "npm run generate && npm run build:esm && npm run build:cjs",
21
+ "build": "npm run build:esm && npm run build:cjs",
22
22
  "build:esm": "tsc --project ./esm.json && tsc-alias -p ./esm.json && npm run build:esm:generatePackageJson",
23
23
  "build:cjs": "tsc --project ./commonjs.json && npm run build:cjs:generatePackageJson",
24
24
  "build:esm:generatePackageJson": "echo '{\\n \"type\": \"module\"\\n}' > dist/esm/package.json",
@@ -27,6 +27,7 @@
27
27
  "typecheck": "tsc --noEmit",
28
28
  "prepare": "npm run build",
29
29
  "prepack": "node node10stubs.mjs",
30
+ "prepublishOnly": "npm run generate && npm run build",
30
31
  "postpack": "node node10stubs.mjs --cleanup",
31
32
  "generate": "concurrently \"cd examples/next && npm run generate\" \"cd examples/react && npm run generate\" \"cd examples/tanstack && npm run generate\"",
32
33
  "test": "vitest run",
@@ -126,13 +127,13 @@
126
127
  }
127
128
  },
128
129
  "peerDependencies": {
129
- "better-auth": "~1.2.12",
130
+ "better-auth": "1.3.4",
130
131
  "convex": ">=1.25.0 <1.35.0",
131
132
  "react": "^18.3.1 || ^19.0.0",
132
133
  "react-dom": "^18.3.1 || ^19.0.0"
133
134
  },
134
135
  "devDependencies": {
135
- "@better-auth/stripe": "1.2.12",
136
+ "@better-auth/stripe": "1.3.4",
136
137
  "@edge-runtime/vm": "^5.0.0",
137
138
  "@eslint/js": "^9.9.1",
138
139
  "@polar-sh/better-auth": "^1.0.4",
@@ -160,7 +161,6 @@
160
161
  "types": "./dist/commonjs/client/index.d.ts",
161
162
  "module": "./dist/esm/client/index.js",
162
163
  "dependencies": {
163
- "@convex-dev/resend": "^0.1.5-alpha.0",
164
164
  "common-tags": "^1.8.2",
165
165
  "convex-helpers": "^0.1.95",
166
166
  "is-network-error": "^1.1.0",
@@ -114,11 +114,10 @@ export class BetterAuth<UserId extends string = string> {
114
114
 
115
115
  async getHeaders(ctx: RunQueryCtx & { auth: ConvexAuth }) {
116
116
  const session = await ctx.runQuery(this.component.lib.getCurrentSession);
117
- return session
118
- ? new Headers({
119
- authorization: `Bearer ${session.token}`,
120
- })
121
- : new Headers();
117
+ return new Headers({
118
+ ...(session?.token ? { authorization: `Bearer ${session.token}` } : {}),
119
+ ...(session?.ipAddress ? { "x-forwarded-for": session.ipAddress } : {}),
120
+ });
122
121
  }
123
122
 
124
123
  // TODO: use the proper id type for auth functions
@@ -74,31 +74,6 @@ const hasUniqueFields = (model: TableNames, input: Record<string, any>) => {
74
74
  return false;
75
75
  };
76
76
 
77
- const checkUniqueFields = async (
78
- ctx: QueryCtx,
79
- table: TableNames,
80
- input: Record<string, any>,
81
- doc?: Doc<any>
82
- ) => {
83
- if (!hasUniqueFields(table, input)) {
84
- return;
85
- }
86
- for (const field of Object.keys(input)) {
87
- if (!isUniqueField(table, field)) {
88
- continue;
89
- }
90
- const existingDoc = await ctx.db
91
- .query(table as any)
92
- .withIndex(field as any, (q) =>
93
- q.eq(field, input[field as keyof typeof input])
94
- )
95
- .unique();
96
- if (existingDoc && existingDoc._id !== doc?._id) {
97
- throw new Error(`${table} ${field} already exists`);
98
- }
99
- }
100
- };
101
-
102
77
  const findIndex = (args: {
103
78
  model: string;
104
79
  where?: {
@@ -242,6 +217,41 @@ const findIndex = (args: {
242
217
  };
243
218
  };
244
219
 
220
+ const checkUniqueFields = async (
221
+ ctx: QueryCtx,
222
+ table: TableNames,
223
+ input: Record<string, any>,
224
+ doc?: Doc<any>
225
+ ) => {
226
+ if (!hasUniqueFields(table, input)) {
227
+ return;
228
+ }
229
+ for (const field of Object.keys(input)) {
230
+ if (!isUniqueField(table, field)) {
231
+ continue;
232
+ }
233
+ const { index } =
234
+ findIndex({
235
+ model: table,
236
+ where: [
237
+ { field, operator: "eq", value: input[field as keyof typeof input] },
238
+ ],
239
+ }) || {};
240
+ if (!index) {
241
+ throw new Error(`No index found for ${table}${field}`);
242
+ }
243
+ const existingDoc = await ctx.db
244
+ .query(table as any)
245
+ .withIndex(index.indexDescriptor, (q) =>
246
+ q.eq(field, input[field as keyof typeof input])
247
+ )
248
+ .unique();
249
+ if (existingDoc && existingDoc._id !== doc?._id) {
250
+ throw new Error(`${table} ${field} already exists`);
251
+ }
252
+ }
253
+ };
254
+
245
255
  const selectFields = <T extends TableNames, D extends Doc<T>>(
246
256
  doc: D | null,
247
257
  select?: string[]
@@ -431,13 +441,18 @@ const paginate = async (
431
441
  (isUniqueField(args.model as TableNames, w.field) || w.field === "id")
432
442
  );
433
443
  if (uniqueWhere) {
444
+ const { index } =
445
+ findIndex({
446
+ model: args.model,
447
+ where: [uniqueWhere],
448
+ }) || {};
434
449
  const doc =
435
450
  uniqueWhere.field === "id"
436
451
  ? await ctx.db.get(uniqueWhere.value as Id<TableNames>)
437
452
  : await ctx.db
438
453
  .query(args.model as any)
439
- .withIndex(uniqueWhere.field as any, (q) =>
440
- q.eq(uniqueWhere.field, uniqueWhere.value)
454
+ .withIndex(index?.indexDescriptor as any, (q) =>
455
+ q.eq(index?.fields[0], uniqueWhere.value)
441
456
  )
442
457
  .unique();
443
458