Problem statement
This article explains a potential cause for Auth0 login and silent authorization requests that take longer than expected despite using actions that contain logic for exiting early.
Symptoms
The action_runtime_ms stats in login logs are longer than expected for the code being executed.
Troubleshooting
Check code for what libraries are in use and in particular whether they are instantiated before the code is exited.
Cause
A potential source of overhead is from instantiating libraries. For example, ‘axios’.
The following example code would always spend some time loading the axios library despite it not being called for a user who had a certain metadata flag:
const axios = require('axios')
exports.onExecutePostLogin = async (event, api) => {
//check if user has a flag that indicates axios call is not required
const metadataFlag = event.user.app_metadata.myCustomFlag
if (metadataFlag) {
// exit early
return
}
// perform axios call...
}
Solution
Moving the axios instantiation to a function that is called only if the correct criteria are met could be a way of reducing this overhead.
The impact of the axios library is relatively small and only given for demonstration purposes, but other, larger libraries may have bigger impacts on runtimes.
For more performance tips, see Performance Best Practices.