@convex-dev/better-auth 0.11.1 → 0.11.3
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-config.d.ts +1 -1
- package/dist/auth-config.d.ts.map +1 -1
- package/dist/auth-options.d.ts.map +1 -1
- package/dist/auth-options.js +11 -2
- package/dist/auth-options.js.map +1 -1
- package/dist/client/adapter-utils.js +2 -2
- package/dist/client/adapter-utils.js.map +1 -1
- package/dist/client/adapter.js +1 -1
- package/dist/client/adapter.js.map +1 -1
- package/dist/client/create-client.d.ts +12 -0
- package/dist/client/create-client.d.ts.map +1 -1
- package/dist/client/create-client.js +92 -0
- package/dist/client/create-client.js.map +1 -1
- package/dist/component/testProfiles/auth-options.profile-rename-joins.js +1 -1
- package/dist/component/testProfiles/auth-options.profile-rename-joins.js.map +1 -1
- package/dist/plugins/convex/index.d.ts.map +1 -1
- package/dist/plugins/convex/index.js +3 -1
- package/dist/plugins/convex/index.js.map +1 -1
- package/dist/plugins/cross-domain/index.d.ts.map +1 -1
- package/dist/plugins/cross-domain/index.js +1 -1
- package/dist/plugins/cross-domain/index.js.map +1 -1
- package/dist/test/adapter-factory/auth-flow.js +5 -5
- package/dist/test/adapter-factory/auth-flow.js.map +1 -1
- package/dist/test/adapter-factory/basic.d.ts.map +1 -1
- package/dist/test/adapter-factory/basic.js +10 -6
- package/dist/test/adapter-factory/basic.js.map +1 -1
- package/dist/test/adapter-factory/convex-custom.d.ts +1 -1
- package/dist/test/adapter-factory/convex-custom.d.ts.map +1 -1
- package/dist/test/adapter-factory/convex-custom.js +55 -1
- package/dist/test/adapter-factory/convex-custom.js.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/auth-config.ts +1 -1
- package/src/auth-options.ts +11 -15
- package/src/client/adapter-utils.ts +2 -2
- package/src/client/adapter.ts +1 -1
- package/src/client/create-client.test.ts +149 -0
- package/src/client/create-client.ts +127 -0
- package/src/component/testProfiles/auth-options.profile-rename-joins.ts +1 -1
- package/src/plugins/convex/index.ts +4 -6
- package/src/plugins/cross-domain/index.ts +1 -1
- package/src/test/adapter-factory/auth-flow.ts +6 -6
- package/src/test/adapter-factory/basic.ts +10 -6
- package/src/test/adapter-factory/convex-custom.ts +58 -1
- package/src/utils/index.ts +1 -1
|
@@ -68,7 +68,11 @@ export const getNormalTestSuiteTests = (
|
|
|
68
68
|
const transformed = transformGeneratedModel(user);
|
|
69
69
|
// console.log(`transformed:`, transformed);
|
|
70
70
|
// console.log(`result:`, result);
|
|
71
|
-
expect(result).toEqual(
|
|
71
|
+
expect(result).toEqual({
|
|
72
|
+
...transformed,
|
|
73
|
+
createdAt: new Date(user.createdAt).getTime(),
|
|
74
|
+
updatedAt: new Date(user.updatedAt).getTime(),
|
|
75
|
+
});
|
|
72
76
|
},
|
|
73
77
|
"create - should always return an id": async () => {
|
|
74
78
|
const { id: _, ...user } = await generate("user");
|
|
@@ -599,7 +603,7 @@ export const getNormalTestSuiteTests = (
|
|
|
599
603
|
where: [{ field: "createdAt", value: user.createdAt, operator: "eq" }],
|
|
600
604
|
});
|
|
601
605
|
expect(result).toEqual(user);
|
|
602
|
-
expect(result?.createdAt).
|
|
606
|
+
expect(typeof result?.createdAt).toBe("number");
|
|
603
607
|
expect(result?.createdAt).toEqual(user.createdAt);
|
|
604
608
|
},
|
|
605
609
|
"findOne - should perform backwards joins": async () => {
|
|
@@ -753,7 +757,7 @@ export const getNormalTestSuiteTests = (
|
|
|
753
757
|
});
|
|
754
758
|
if (result?.session?.length) {
|
|
755
759
|
result.session = result.session.sort(
|
|
756
|
-
(a, b) => a.createdAt
|
|
760
|
+
(a, b) => (a.createdAt as unknown as number) - (b.createdAt as unknown as number),
|
|
757
761
|
);
|
|
758
762
|
}
|
|
759
763
|
|
|
@@ -869,7 +873,7 @@ export const getNormalTestSuiteTests = (
|
|
|
869
873
|
"findMany - should find many models with date fields": async () => {
|
|
870
874
|
const users = (await insertRandom("user", 3)).map((x) => x[0]);
|
|
871
875
|
const youngestUser = users.sort(
|
|
872
|
-
(a, b) => b.createdAt
|
|
876
|
+
(a, b) => (b.createdAt as unknown as number) - (a.createdAt as unknown as number),
|
|
873
877
|
)[0]!;
|
|
874
878
|
const result = await adapter.findMany<User>({
|
|
875
879
|
model: "user",
|
|
@@ -1709,7 +1713,7 @@ export const getNormalTestSuiteTests = (
|
|
|
1709
1713
|
"findMany - should find many models with gt operator": async () => {
|
|
1710
1714
|
const users = (await insertRandom("user", 3)).map((x) => x[0]);
|
|
1711
1715
|
const oldestUser = users.sort(
|
|
1712
|
-
(a, b) => a.createdAt
|
|
1716
|
+
(a, b) => (a.createdAt as unknown as number) - (b.createdAt as unknown as number),
|
|
1713
1717
|
)[0]!;
|
|
1714
1718
|
const result = await adapter.findMany<User>({
|
|
1715
1719
|
model: "user",
|
|
@@ -1730,7 +1734,7 @@ export const getNormalTestSuiteTests = (
|
|
|
1730
1734
|
"findMany - should find many models with gte operator": async () => {
|
|
1731
1735
|
const users = (await insertRandom("user", 3)).map((x) => x[0]);
|
|
1732
1736
|
const oldestUser = users.sort(
|
|
1733
|
-
(a, b) => b.createdAt
|
|
1737
|
+
(a, b) => (b.createdAt as unknown as number) - (a.createdAt as unknown as number),
|
|
1734
1738
|
)[0]!;
|
|
1735
1739
|
const result = await adapter.findMany<User>({
|
|
1736
1740
|
model: "user",
|
|
@@ -199,6 +199,63 @@ export const convexCustomTestSuite = createTestSuite(
|
|
|
199
199
|
).toEqual(user);
|
|
200
200
|
},
|
|
201
201
|
|
|
202
|
+
"should use composite index for eq + sortBy on second field": async () => {
|
|
203
|
+
const sharedExpiresAt = Date.now() + 60_000;
|
|
204
|
+
await adapter.create({
|
|
205
|
+
model: "session",
|
|
206
|
+
data: {
|
|
207
|
+
token: `tok-z-${sharedExpiresAt}`,
|
|
208
|
+
expiresAt: sharedExpiresAt,
|
|
209
|
+
userId: "zzz-user",
|
|
210
|
+
createdAt: sharedExpiresAt,
|
|
211
|
+
updatedAt: sharedExpiresAt,
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
await adapter.create({
|
|
215
|
+
model: "session",
|
|
216
|
+
data: {
|
|
217
|
+
token: `tok-a-${sharedExpiresAt}`,
|
|
218
|
+
expiresAt: sharedExpiresAt,
|
|
219
|
+
userId: "aaa-user",
|
|
220
|
+
createdAt: sharedExpiresAt,
|
|
221
|
+
updatedAt: sharedExpiresAt,
|
|
222
|
+
},
|
|
223
|
+
});
|
|
224
|
+
await adapter.create({
|
|
225
|
+
model: "session",
|
|
226
|
+
data: {
|
|
227
|
+
token: `tok-m-${sharedExpiresAt}`,
|
|
228
|
+
expiresAt: sharedExpiresAt,
|
|
229
|
+
userId: "mmm-user",
|
|
230
|
+
createdAt: sharedExpiresAt,
|
|
231
|
+
updatedAt: sharedExpiresAt,
|
|
232
|
+
},
|
|
233
|
+
});
|
|
234
|
+
await adapter.create({
|
|
235
|
+
model: "session",
|
|
236
|
+
data: {
|
|
237
|
+
token: `tok-non-matching-${sharedExpiresAt}`,
|
|
238
|
+
expiresAt: sharedExpiresAt + 60_000,
|
|
239
|
+
userId: "bbb-user",
|
|
240
|
+
createdAt: sharedExpiresAt,
|
|
241
|
+
updatedAt: sharedExpiresAt,
|
|
242
|
+
},
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
const result = await adapter.findMany<{ userId: string }>({
|
|
246
|
+
model: "session",
|
|
247
|
+
where: [{ field: "expiresAt", value: sharedExpiresAt }],
|
|
248
|
+
sortBy: { field: "userId", direction: "asc" },
|
|
249
|
+
select: ["userId"],
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
expect(result.map((session) => session.userId)).toEqual([
|
|
253
|
+
"aaa-user",
|
|
254
|
+
"mmm-user",
|
|
255
|
+
"zzz-user",
|
|
256
|
+
]);
|
|
257
|
+
},
|
|
258
|
+
|
|
202
259
|
"should automatically paginate": async () => {
|
|
203
260
|
for (let i = 0; i < 300; i++) {
|
|
204
261
|
await adapter.create({
|
|
@@ -700,7 +757,7 @@ export const convexCustomTestSuite = createTestSuite(
|
|
|
700
757
|
where: [{ field: "createdAt", value: now }],
|
|
701
758
|
}),
|
|
702
759
|
).toEqual(user);
|
|
703
|
-
expect(user.createdAt).
|
|
760
|
+
expect(typeof user.createdAt).toBe("number");
|
|
704
761
|
},
|
|
705
762
|
}),
|
|
706
763
|
);
|
package/src/utils/index.ts
CHANGED
|
@@ -13,7 +13,7 @@ import { JWT_COOKIE_NAME } from "../plugins/convex/index.js";
|
|
|
13
13
|
import * as jose from "jose";
|
|
14
14
|
import type { Jwk } from "better-auth/plugins/jwt";
|
|
15
15
|
|
|
16
|
-
type TrustedOriginsOption =
|
|
16
|
+
export type TrustedOriginsOption =
|
|
17
17
|
| (string | null | undefined)[]
|
|
18
18
|
| ((
|
|
19
19
|
request?: Request
|