Logout and redirect if server is unreachable

Hi, i am quite new to Meteor and I’m working on an app thats using Iron.Router. I have run in to an issue i can’t seem to find an answer too. In short: I need the client to log the user out and redirect to the login screen if the server is unavailable for any reason (i.e. the server restarted).

Currently the client reconnects to the server when its available again, and shows a modal while its unavailable.

I have tried a few different approaches, but none seems to work as i want them to. Some of the things I’ve tried:

  • Setting a function for Meteor.default_connection.onReconnect - A console.log inside the function prints in the console, but using Meteor.logout() doesn’t seem to do anything.
  • Using Tracker.autorun and check Meteor.status().connected - Same as above, i can output stuff with console.log, but meteor.logout() does nothing.
  • I tried to get something working using a heartbeat call to a method on the server, but it didn’t really pan out; at least not yet.

I would be fine if the redirection and logout process happened upon reconnecting, and the modal showing while its not able to connect. The app does not have to be accessible “offline”.

Appreciate any help, ideas or thoughts on this.

I am aware the issue is quite similar to this one: How to redirect a user after server-side logout with Accounts.setPassword? but i didn’t want to hijack his thread.