Search code examples
authenticationsettingsdrupal-8user-registration

Failed User Login | Drupal 8


I have developed a website in Drupal 8 and have deployed it to production. I have created 7-8 other accounts for my content management team and have granted them limited privileges for creating, editing and deleting content.

Of late, I am facing a problem with the user login form, wherein the login works sporadically. Sometimes I am able to log in as the administrator in the first attempt, sometimes I am not. In the latter case, I have to reset my password via email using the reset password option. However, this approach works only temporarily for a single session, which means that as soon as I log out, I am unable to log in. My content managers are also experiencing the same problem.

I have tried the below things but no luck.

  1. Truncating the flood, session, and all the cache tables and flood table manually from the database.

  2. Disabling the Recaptcha module in the login form.

  3. Enabling and disabling the HTTP Basic Authentication module.

  4. Disabling server proxy configuration through the settings.php file.

  5. Performing Drupal updates by running the update.php file.

  6. The incorrect username and/or password error in the login has not been handled. When an incorrect username/password is entered the page only refreshes without displaying any custom message.

Edit: I have just observed that I had luckily forgotten to log out as the super admin on the site from another browser, Firefox. I investigated further to fix this problem and observed a pattern. I am able to login as the administrator when I manually clear the cache from Firefox (where I luckily forgot to logout). However, this works only for one session, which means after logging out the bug reappears. In order to make the login to again work as expected, I have to again clear the cache from Firefox.


Solution

  • Okay, after much banging my head over the wall for nearly a week, I have found a workarpund solution to this problem by uninstalling Internal Dynamic Page Cache and Internal Page Cache modules.

    The problem was that the user login form was getting cached after one successful login. Using the Chrome developer tools the following response header was getting set and sent by Drupal.

    X-Drupal-Dynamic-Cache: HIT
    

    To elimnate this I had to uninstall the above two modules.

    However this is just a workaround and not a solution, since disabling these two modules will have a tradeoff with the site performance.

    Anyone who knows the solution to this problem, please post it here. I shall try them and update this space.

    Thank you in advance.