28 lines
623 B
JavaScript
Raw Normal View History

'use strict';
2022-08-08 23:33:39 +02:00
module.exports =
(config, { strapi }) =>
async (ctx, next) => {
const ratelimit = require('koa2-ratelimit').RateLimit;
2021-09-03 11:11:37 +02:00
2022-08-08 23:33:39 +02:00
const message = [
{
messages: [
{
id: 'Auth.form.error.ratelimit',
message: 'Too many attempts, please try again in a minute.',
},
],
},
];
2018-08-01 14:56:31 +02:00
2022-08-08 23:33:39 +02:00
return ratelimit.middleware({
interval: 1 * 60 * 1000,
max: 5,
prefixKey: `${ctx.request.path}:${ctx.request.ip}`,
message,
...strapi.config.get('plugin.users-permissions.ratelimit'),
...config,
})(ctx, next);
};