Thank you for your response. The root cause of this issue had to do with the post-login script being called more than once. We consulted with the support team, who referred us to this:
Adding in the condition (to check whether MFA had already been enabled) solved the problem for us.