2019-04-05 16:11:09 +02:00
|
|
|
const lazyRateLimit = {
|
|
|
|
get RateLimit() {
|
|
|
|
return require('koa2-ratelimit').RateLimit;
|
|
|
|
},
|
|
|
|
};
|
2018-08-01 14:56:31 +02:00
|
|
|
|
|
|
|
module.exports = async (ctx, next) => {
|
2019-04-05 16:11:09 +02:00
|
|
|
const message = ctx.request.admin
|
|
|
|
? [{ messages: [{ id: 'Auth.form.error.ratelimit' }] }]
|
|
|
|
: 'Too many attempts, please try again in a minute.';
|
2018-08-01 14:56:31 +02:00
|
|
|
|
2019-04-05 16:11:09 +02:00
|
|
|
return lazyRateLimit.RateLimit.middleware(
|
|
|
|
Object.assign(
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
interval: 1 * 60 * 1000,
|
|
|
|
max: 5,
|
|
|
|
prefixKey: `${ctx.request.url}:${ctx.request.ip}`,
|
|
|
|
message,
|
|
|
|
},
|
|
|
|
strapi.plugins['users-permissions'].config.ratelimit
|
|
|
|
)
|
|
|
|
)(ctx, next);
|
2018-08-01 14:56:31 +02:00
|
|
|
};
|