I have a page with a few buttons. When people click on the buttons they issue AJAX requests and update various parts of the page. The AJAX requests make use of nonces for security purposes.
I noticed that if someone leaves the page open for longer than the time it takes for a nonce to expire, then the AJAX requests will stop working as expected. However, I would want a bit more of a robust behavior.
What I'd want to do is - detect when a nonce has expired / failed, and then at that point somehow generate a new nonce.
So this is a two part question:
- How can I detect that the nonce has expired?
- Is the best thing to do on expired nonce a full page refresh, or something else? I'm not super versed in security considerations. I would want to carry over the current page status though (so any of the selected options in the various ajax requesting parts of the page) after the page refresh.