Redirect works just once

Created on 17 February 2023, almost 2 years ago
Updated 10 March 2023, over 1 year ago

Problem/Motivation

I created a simple model which should redirect a guest user when he wants to see a node of type event. After logging off and test this, the redirect works once. At the second time, the node is shown.

Steps to reproduce

Feel free to import the appended model and switch the type of node to one of your choice.

💬 Support request
Status

Fixed

Version

1.1

Component

Code

Created by

🇩🇪Germany ab_connor

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Issue created by @ab_connor
  • 🇩🇪Germany jurgenhaas Gottmadingen

    This is due to caching. As you're using the "View content entity" event, this won't be triggered once that entity got viewed once, e.g. by an authenticated user, and therefore got cached. That's why it will be in cache and Drupal delivers the cached version the next time this entity is being requested.

    You can resolve this by either invalidating the cache for such nodes, or you change the event to react upon. In the ECA Guide library, there is an example which redirects users on 403 to the login page, you may want to download that and modify that towards you requirements.

  • 🇩🇪Germany jurgenhaas Gottmadingen
  • 🇩🇪Germany ab_connor

    Thanks for your support. I tried to invalidate the cache for nodes from type "event" by using the task "cache invalidate". But I'm not really familiar with cache keys. What would be the right entry for it? I tried "entity_view" and some others without any success. And can I use "node:[entity:nid]" in the tags field for a granular invalidating?

  • 🇩🇪Germany jurgenhaas Gottmadingen

    I thought about it again and the cache invalidation approach isn't what I should have suggested. Going with the redirect sample is certainly a better way.

    A third option might be the eca_access module. That way you could define different access rules depending on user role.

  • Status changed to Postponed: needs info over 1 year ago
  • 🇩🇪Germany ab_connor

    Yes, thanks for your support.

  • Status changed to Fixed over 1 year ago
  • 🇩🇪Germany mxh Offenburg
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024