Custom List Icon Bad URL causes site to logout after 5 seconds
Describe the bug
If the URL for a custom list item icon points to a resource that doesn't exist within the DT server, the response will come back as a 302 error. That for some reason clears the logged in cookie, so the later API calls, in my case the get_new_notifications_count call will fail and the user will be logged out. This will happen on every page that the icon with the faulty URL appears.
To Reproduce Steps to reproduce the behavior:
- Create a custom list icon but point it to a URL that doesn't exist. In my case I was on a multisite instance so it was pointing to
/wp-content/images/instead ofwp-content/themes/disciple-tools-theme-master/dt-assets/images/ - Load the page with that item on the front end. In the Dev tools Network tab you will see the get_new_notifications_count eventually fail and the user will be sent to the login screen.
- Trying to remove the item from the wp-admin seems to fail as well and I am asked to login every time I try to save the item with a new URL or delete it.
The only way I could fix this to go into the DB into the options table and edit the value for dt_field_customizations to change the URL.
There are at least 2 approaches to fixing this. First, put some verification that the URL is pointing to an accessible resource when the item is saved, but if the item is deleted later we could still have the same problem. Option 2 is to figure out why the user is logged out when it hits a bad resource like this.
Check for new notifications every 5 mins, if that fails (auth expired) then reload. https://github.com/DiscipleTools/disciple-tools-theme/blob/da44754b0904f3e469f1d6dde6e2e41c0aeddbb9/dt-assets/js/notifications.js#L298
The auto sign out issue i think was related to something else. I'll try to find it.
Still Todo: Option 2 is to figure out why the user is logged out when it hits a bad resource like this.