PrestaShop icon indicating copy to clipboard operation
PrestaShop copied to clipboard

Error 302: ERR_TOO_MANY_REDIRECTS in Back Office

Open mtdkbusiness opened this issue 11 months ago • 9 comments

Prerequisites

Describe the bug and add attachments

Hello,

I would like to set up a local Docker-based development environment for theme and plugin development. The environment would be a copy of the existing store, however, I have encountered an issue. Despite completing the migration steps and adjusting the configuration settings, I cannot log into PrestaShop Back Office (BO). After migrating the database and setting the store's URLs in the appropriate tables in the database, the store seems to work locally at first sight. However, I can't log into the admin panel because when I try to access the Back Office (from the URL I defined in the PS_FOLDER_ADMIN environment variable in docker-compose.yaml), the site falls into redirect loop (error 302 - ERR_TOO_MANY_REDIRECTS). Has anyone of you encountered this issue before and is able to help me solve it?

Here's what I've done so far:

  • I downloaded a database dump of the existing store.
  • I configured docker-compose and set up a clean store locally.
  • I imported the downloaded database dump.
  • I updated the appropriate values in the PS_CONFIGURATION and PS_SHOP_URL tables.
  • I deleted the cache files and even tried deleting the .htaccess file.

Additional information:

  • Prestashop version: 8.1.4
  • MySQL version: 5.7

The problem persists in different browsers, which rules out a cookie issue. Thank you in advance for your help!

Expected behavior

Back Office should work without any problems.

Steps to reproduce

  1. Download a database dump of the existing store.
  2. Configure docker-compose and set up a clean store locally.
  3. Import the downloaded database dump.
  4. Update the appropriate values in the PS_CONFIGURATION and PS_SHOP_URL tables.

PrestaShop version(s) where the bug happened

8.1.4

PHP version(s) where the bug happened

No response

If your bug is related to a module, specify its name and its version

No response

Your company or customer's name goes here (if applicable).

No response

mtdkbusiness avatar Mar 26 '24 22:03 mtdkbusiness

Hello @mtdkbusiness,

Thanks for reporting this issue! Ping @PrestaShop/prestashop-core-developers : Could someone please try to reproduce the issue, it's too technical!

Thanks in advance!

paulnoelcholot avatar Mar 27 '24 09:03 paulnoelcholot

Hello @mtdkbusiness , do you have the PS_SSL_ENABLED configuration enabled ?

M0rgan01 avatar Mar 27 '24 17:03 M0rgan01

I had SSL enabled on the production site and of course after the database migration, in addition to changing the site URLs in the database, I also changed the values of PS_SSL_ENABLED and PS_SSL_ENABLED_EVERYWHERE to 0 in PS_CONFIGURATION table.

mtdkbusiness avatar Mar 27 '24 23:03 mtdkbusiness

@mtdkbusiness I assume that the source and destination stores are both 8.1.4? Are there any errors in the docker/ docker compose logs? Did you make any changes to app/config/parameters.php (e.g. to move over the crypto keys for user passwords etc.)?

I can try and replicate it here with a docker 8.1.4 site if you can provide the yaml you used (redacted for any confidential information).

paulc010 avatar Mar 30 '24 19:03 paulc010

I almost gave up, but finally managed to find a solution to my problem.... During desperate attempts to "transplant" individual database tables from a clean store database to my imported database (which comes from a production environment), I found that rewriting the "ps_tab" table restores the possibility to get to backoffice eliminating the problem of redirect loops.

Honestly, I have no idea what exactly the problem is (inconsistency of data structure in the tables between my production PrestaShop instance and the local Docker instance?), but I don't even have the strength to analyze it anymore. I hope this topic will help someone struggling with a similar problem someday.

mtdkbusiness avatar May 06 '24 18:05 mtdkbusiness

Hi @mtdkbusiness

Just deleted because don't have relation with PrestaShop but with PrestaShopCorp, and PrestaShop is also reworking the way admin logs in, but since you care I'll post it again.

You're right, the issue resides on ps_tab, found it yesterday and just searched for ERR_TOO_MANY_REDIRECTS to find this issue.

The issue:

Modules like ps_accounts adds it's own route to their own admin login controller, and if a merchant ~~uninstall~~ and deletes this module the route is not deleted (didn't investigate why, had no time) and is never found, that's why we get ERR_TOO_MANY_REDIRECTS.

PrestaShop could check if the module is installed before trying to use a nonexistent controller.

[EDIT]

Just tested on my end and the ps_accounts tabs are deleted after module is uninstalled, strange things happens some times on merchants sites.

And at your end you just added them when dumping the DB and maybe the module was not installed at all so it's obvious why it fails.

Also my recommendation is not to dump DB like that, I even read this in docs few years ago, so if you're not gonna clone the site, there are some tables that have to be populated by PrestaShop or these issues could happen and some others we don't see but are there.

[EDIT 2]

Revising logs I discovered why the tabs were not deleted, the merchant just disabled the ps_accounts module and then deleted the folder.

To reproduce, we can run the following commands:

./bin/console prestashop:module install ps_accounts

./bin/console prestashop:module enable ps_accounts

./bin/console prestashop:module disable ps_accounts

mv modules/ps_accounts modules/ps_accounts_

Try to log into BO and get ERR_TOO_MANY_REDIRECTS

Delete all ps_accounts rows on ps_tab table and login works as expected.

DELETE FROM ps_tab WHERE module = 'ps_accounts'

ChillCode avatar May 07 '24 07:05 ChillCode

So it seems that the problem does not only affect me. @M0rgan01 - do you need help in reproducing the issue despite the above details?

Also my recommendation is not to dump DB like that, I even read this in docs few years ago, so if you're not gonna clone the site, there are some tables that have to be populated by PrestaShop or these issues could happen and some others we don't see but are there.

@ChillCode - so what is your recommendation in terms of plugin/theme development for an existing store?

mtdkbusiness avatar May 10 '24 09:05 mtdkbusiness

@ChillCode I agree that the store should assert that a class specified in the ps_tab table exists before trying to instantiate it. This would solve a whole lot of problems with people upgrading and relocating stores (it's too easy to forget to copy a module over). The module handling is much more robust than the back office menu system.

If I can find time I can look at doing a low-impact pull request that mitigates these types of issues.

paulc010 avatar May 10 '24 09:05 paulc010

@paulc010 I tried to clone dev branch few weeks ago but I couldn't since I had no space on the instance, but last merge https://github.com/PrestaShop/PrestaShop/pull/35983, note that devs do a huge work, should give different results since it migrated BO login to Symfony.

In stable branch 8.1 AdminLogin is a critical controller and PrestaShop is in limbo if the module is not present that's why redirects endlessly. When we are logged as admin is when we get controller not found error, is no that critical, but the issue in general is trivial and caused by third-party modules or bad migrations or implementations.

@mtdkbusiness Is good to read dev docs, is where I learned more about PrestaShop, you can find more about this at the following link were it says These tables can be ignored as well so it means those are tables that have to be populated by PrestaShop, so now I just clone sites and run my scripts and for module dev I use the latest stable branch and install them in env prod after testing.

ChillCode avatar May 10 '24 16:05 ChillCode