medic / cht-core

The CHT Core Framework makes it faster to build responsive, offline-first digital health apps that equip health workers to provide better care in their communities. It is a central resource of the Community Health Toolkit.
https://communityhealthtoolkit.org
GNU Affero General Public License v3.0
468 stars 217 forks source link

Implement heartbeat to detect 401s for admin users #1978

Closed SCdF closed 5 years ago

SCdF commented 8 years ago

See #1931 .

The above ticket can solve issues with Pouch users because there are only so many places they touch the network (some boot strapping, pouch replication etc).

Admin users are more complicated, since all their interactions go straight to the net.

To generically solve this we should create a heartbeat that pings a resource that is known to be tiny and behind auth, and if we ever get a 401 back redirect to the log in page.

alxndrsn commented 8 years ago

Admin users are more complicated, since all their interactions go straight to the net.

All admin users' interactions go through pouch, so you may not need special handling for them.

SCdF commented 8 years ago

All admin users' interactions go through pouch, so you may not need special handling for them.

Ideally there would be a Pouch hook where we say something like:

pouchDbInstance.on('error', function(err) {
  if (err.status === 401) {
    return Session.redirectToLogin();
  }
});

Unfortunately the only ones I've found documentation for is created and destroyed (ie for changes to documents), which isn't really helpful here. I'm too new to Javascript to know if there is a way we can just hook into the event model regardless of what Pouch wants us to do.

alxndrsn commented 8 years ago

Point of pedantry: I think create and destroy events refer to databases rather than docs: http://pouchdb.com/api.html#events

SCdF commented 8 years ago

Yep sorry you're right. Which is even weirder, since you'd think you would care even less about those events.

nice-snek commented 7 years ago

hi frand @browndav, please triage before the end of this sprint. :parrot_conga::parrot_conga::parrot_conga:

garethbowen commented 7 years ago

Related: #3299 #3254

ghost commented 7 years ago

This appears valuable; removing "needs triage" label and placing in deprioritized mobile app features milestone.

garethbowen commented 5 years ago

This should be fixed by #3919 - adding to AT to make sure.

ngaruko commented 5 years ago

Fixed by #3919 - with improvement suggestions in #5772 .