Permanent (periodic) check of value - How best to implement?


I have this field/value in the storage of my app that should periodically be checked by some kind of process in the app. If some condition applies it should trigger some special code to be executed.

How do I best implement this?

(Example: I have an account that is saved in localStorage. It has an expires_at field. Now when the user uses the app the value should be checked against the current date and trigger a relogin window. If this doesn’t work the next network will fail with a 401 http error code and this will trigger the relogin window too, but I would prefer to not having to to that extra request that will fail anyway.)

My current theory is to check the events of the app start, pause, resume etc. and maybe add some timer if a user should use the app all day - or to find some way to execute this smll check every time a user uses the app (code in a controller gets executed?). But I have no idea if this is a good way to go about this or if I am missing something.

All feedback and suggestions appreciated, thanks.