How to avoid "The form has become outdated" after login in separate tab I've read this and this and I can't see how to apply that to my situation, so asking another question.


not-logged in user visits a page with a form on it.
User opens a new tab and logs in.
User switches back to their first tab and tries to submit the form.
Gets the outdated error.


How can I accept the anonymous form submissions once logged in?

In my application it's quite possible that the user has quite a few pages open in different tabs before they log in.
The error is related to form CSRF protection, the error message comes from core form validation.

To avoid the error, it's possible to remove that CSRF token validation check in hook_form_alter e.g:

function my_module_form_alter(&amp;$form, &amp;$form_state, $id) {
  if (strpos($id, 'webform') === 0) {
    // Bypass per user CSRF token check and allow cache.
    unset($form['#token']);
  }
}


The caveat is, the form will no longer have default CSRF protection.

Alternatively, you might be able to detect the user has logged in (e.g custom local storage set event) and reload the original page to refresh it as is.