[Solved] 2FA Endless Login Loop
# help-with-umbraco
c
V13.6.0 Hi, I have a site where I've used the Umbraco provided login partial to allow members to log in. Works fine (apart from failed log in, see previous post!). Now added 2FA as per the Umbraco docs. From initial log in the QR code comes up and works fine, I put the code into the box and I'm in, no problem. However, if I then log out and back in again, when I enter my username and password, I'm immediately returned to the login page and I haven't been logged in. I'm stuck in an endless loop I can't get out of. So initially, the login page redirects to the 2FA page, QR code displayed, code entered, all good. Logging out and in again, the login page redirects back to itself eternally. I don't see any way of intervening as it doesn't respect the
loginModel.RedirectUrl
provided. I initially thought it was because there was some detection of 2FA providers in the login page, but I tried commenting all that out and it still doesn't respect the redirect and unless there's something in the returned model. I tried utilising the returned ViewData but it doesn't work, it just comes back to the log in form because it's hasn't logged itself in, so attempting to get to the 2FA page fails.
Copy code
@if (ViewData["TwoFactorRequired"]?.ToString() == "UmbracoAppAuthenticator") {
    <script>
        window.location.href="/2FAPage";
    </script>
}
Any ideas gratefully received. Thanks.
Just bumping this as it's Monday 😉
For those that arrive here with a similar conundrum, I worked out I needed to add a hidden field of "returnUrl" and it finally worked.
Copy code
@using (Html.BeginUmbracoForm<UmbTwoFactorLoginController>(nameof(UmbTwoFactorLoginController.Verify2FACode))) {
         <text>
               <input type="hidden" name="returnUrl" value="/secure/dashboard"/>
12 Views