We are currently using rate limiter which from my understanding limits requests per user IP. Example code below
import rateLimit from 'express-rate-limit'
const apiLimiter = rateLimit({
windowMs: 10000, // 10 seconds
max: 1,
standardHeaders: true,
legacyHeaders: false,
})
app.use('/api', apiLimiter, //endpoint)
Is it possible to use rate limiter per userId incase requests are sent from multiple devices at once which will have different IPs
Yes, you can set a custom
keyGeneratorto return a userId rather than an IP address:The
keyGeneratorfunction may also beasyncor return aPromiseif you can't determine userId synchronously.Disclosure: I'm the author of express-rate-limit.