diff --git a/src/client/create-schema.ts b/src/client/create-schema.ts index d8163a71..341854ce 100644 --- a/src/client/create-schema.ts +++ b/src/client/create-schema.ts @@ -5,7 +5,7 @@ import type { BetterAuthDBSchema, DBFieldAttribute } from "better-auth/db"; export const indexFields = { account: ["accountId", ["accountId", "providerId"], ["providerId", "userId"]], rateLimit: ["key"], - session: ["expiresAt", ["expiresAt", "userId"]], + session: ["expiresAt", ["expiresAt", "userId"], ["token", "expiresAt"]], verification: ["expiresAt", "identifier"], user: [["email", "name"], "name", "userId"], oauthConsent: [["clientId", "userId"]], @@ -129,8 +129,8 @@ export const tables = { mergedIndexFields(tables)[ tableKey as keyof typeof mergedIndexFields ]?.map((index) => { - const indexArray = Array.isArray(index) ? index.sort() : [index]; - const indexName = indexArray.join("_"); + const indexArray = Array.isArray(index) ? index : [index]; + const indexName = [...indexArray].sort().join("_"); return `.index("${indexName}", ${JSON.stringify(indexArray)})`; }) || []; diff --git a/src/component/schema.ts b/src/component/schema.ts index 82bd97ab..aee6a965 100644 --- a/src/component/schema.ts +++ b/src/component/schema.ts @@ -44,6 +44,7 @@ export const tables = { .index("expiresAt", ["expiresAt"]) .index("expiresAt_userId", ["expiresAt","userId"]) .index("token", ["token"]) + .index("token_expiresAt", ["token","expiresAt"]) .index("userId", ["userId"]), account: defineTable({ accountId: v.string(),