hapi-rate-limiter
hapi-rate-limiter copied to clipboard
Error in defining an async rate limit function
I'm trying to define a dynamic rate limit based upon the user's role. To achieve this, the user details has to be fetched from db (redis) and then evaluated via async/await.
customRate = async(request){
// read the details from db/cache
user = await getUserDetails(request.auth.credentials.id);
if(user.isAdmin){
return {limit: 10, window: 60};
}
return {limit : 5, window: 60};
}
server.route([{
method: 'POST',
path: '/custom_rate_route',
config: {
plugins: {
rateLimit: {
enabled: true
rate: (request) => customRate
}
},
handler: (request) => {
return { rate: request.plugins['hapi-rate-limiter'].rate };
}
}
}]);
However, defining such an async function throws an error
node_redis: Deprecated: The EVALSHA command contains a "undefined" argument. This is converted to a "undefined" string now and will return an error from v.3.0 on. Please handle this in your code to make sure everything works as you intended it to.
I'm guessing the function does not expect a promise. How do we solve this scenario?