31 lines
642 B
JavaScript
Raw Normal View History

'use strict';
module.exports = (config, { strapi }) => async (ctx, next) => {
2021-09-03 11:11:37 +02:00
const ratelimit = require('koa2-ratelimit').RateLimit;
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
2021-09-03 11:11:37 +02:00
return ratelimit.middleware(
2019-04-05 16:11:09 +02:00
Object.assign(
{},
{
interval: 1 * 60 * 1000,
max: 5,
prefixKey: `${ctx.request.path}:${ctx.request.ip}`,
2019-04-05 16:11:09 +02:00
message,
},
strapi.config.get('plugin.users-permissions.ratelimit'),
config
2019-04-05 16:11:09 +02:00
)
)(ctx, next);
2018-08-01 14:56:31 +02:00
};