The reason you are getting that error is, that code specifies the home page(‘/’) as the default redirect location if no login redirects found for that user. But your home page also uses this template. So it goes into a redirect loop. You will have the same error, if the URL configured within the login redirect uses the same template/code.
To fix the error, change the default location to a URL which do not use this template/code. For example, change it to ‘/abc/’ and make sure page ABC do not use this template/code.
So your code will change like this.
Let me know if it doesn’t work.