34 lines
661 B
JavaScript
Raw Normal View History

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