mirror of
https://github.com/better-auth/better-auth.git
synced 2026-10-20 20:26:55 -05:00
fix(core): consolidate rateLimit table schema definition (#7551)
This commit is contained in:
@@ -1284,42 +1284,6 @@ export const createAdapterFactory =
|
||||
delete tables.session;
|
||||
}
|
||||
|
||||
if (
|
||||
options.rateLimit &&
|
||||
options.rateLimit.storage === "database" &&
|
||||
// rate-limit will default to enabled in production,
|
||||
// and given storage is database, it will try to use the rate-limit table,
|
||||
// so we should make sure to generate rate-limit table schema
|
||||
(typeof options.rateLimit.enabled === "undefined" ||
|
||||
// and of course if they forcefully set to true, then they want rate-limit,
|
||||
// thus we should also generate rate-limit table schema
|
||||
options.rateLimit.enabled === true)
|
||||
) {
|
||||
tables.ratelimit = {
|
||||
modelName: options.rateLimit.modelName ?? "ratelimit",
|
||||
fields: {
|
||||
key: {
|
||||
type: "string",
|
||||
unique: true,
|
||||
required: true,
|
||||
fieldName: options.rateLimit.fields?.key ?? "key",
|
||||
},
|
||||
count: {
|
||||
type: "number",
|
||||
required: true,
|
||||
fieldName: options.rateLimit.fields?.count ?? "count",
|
||||
},
|
||||
lastRequest: {
|
||||
type: "number",
|
||||
required: true,
|
||||
bigint: true,
|
||||
defaultValue: () => Date.now(),
|
||||
fieldName:
|
||||
options.rateLimit.fields?.lastRequest ?? "lastRequest",
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
return adapterInstance.createSchema!({ file, tables });
|
||||
}
|
||||
: undefined,
|
||||
|
||||
@@ -32,16 +32,21 @@ export const getAuthTables = (
|
||||
fields: {
|
||||
key: {
|
||||
type: "string",
|
||||
unique: true,
|
||||
required: true,
|
||||
fieldName: options.rateLimit?.fields?.key || "key",
|
||||
},
|
||||
count: {
|
||||
type: "number",
|
||||
required: true,
|
||||
fieldName: options.rateLimit?.fields?.count || "count",
|
||||
},
|
||||
lastRequest: {
|
||||
type: "number",
|
||||
bigint: true,
|
||||
required: true,
|
||||
fieldName: options.rateLimit?.fields?.lastRequest || "lastRequest",
|
||||
defaultValue: () => Date.now(),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user