Score:1

How do I deal with the problem of stale cookies breaking logins on a migrated site?

sa flag

I just finished the migration of a D7 site into D9.

Unfortunately, as I kept the same domain, before the first time I login to the new D9 site, I have to remove my domain's cookies from within my browser. If I don't remove the cookies, I can't login. (I assume there is some kind of conflict between the D7 cookies and the D9 login process)

My idea is to create a form with a submit button which will remove the D7 cookies.

Here is my code:

  public function submitForm(array &$form, FormStateInterface $form_state) {
    $cookies = \Drupal::request()->cookies;
    foreach ($cookies as $cookie) {
      setcookie($cookie, "", time() - 3600);
    }
  }

I am not sure If I need to remove all cookies... which one should be deleted? Also, this code fail because some cookie name have coma like eF8gbELtR4DO6pRrsjgk1J,XFZlXH83j28-5ssIcvBPz,zsw

id flag
This is a known bug https://www.drupal.org/project/drupal/issues/2868384
Baud avatar
sa flag
Many thanks!!!! you saved my day!
Score:2
id flag

This is a known bug when migrating from Drupal 7. Use one of the patches on that issue. In the current form these patches work by introducing an optional session_suffix session service configuration. By configuring that value in services.yml with a short string you will effectively invalidate all session cookies.

Baud avatar
sa flag
Unfortunately, I have patched the core files (#56 for 9.5) but the reset password process lead to an access denied page. Removing the cookies solve this issue. I am back to my original question: I would like to create a form which remove the cookies (to avoid to explain to all users how to do it)
Baud avatar
sa flag
Thanks to your help, I could make it work by adding the `session_suffix` key in my `services.yml` file. This key should be present in the `default.services.yml` file after you have applied the patch. You can copy it in your own `services.yml` file and add a value for it. It could be nice to add this explanation in your answerr...
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.