How do you trigger from `Accounts.validateLoginAttempt` that the user has to `sign-in` again on `resume` event?

Here’s my problem. The user still has the app running, however he’s logged out due to 15 minutes inactivity by my Backend app (separate app).

When the user is using the app again, it rightfully triggers a resume event that is captured in Accounts.validateLoginAttempt in the server code of my frontend app.

I’m returning false for this login attempt and it should therefore bring the user back to the login modal. However, it doesn’t happen and the user ends up with an unresponsive app (apart from forcing a refresh by CTRL-R) as his connection to the Backend server is cut and the app still believes that there’s a connection. So no reactive data changes are received.

I’ve tried setting 'status.online': false but to no avail.

resume condition is identified through options.allowed === false and options.user === undefined.

Sending an event/msg to the frontend from the backend is a general problem, how do you solve this in general? The only option I see is to throw a Meteor.Error which isn’t the nicest way.

Thanks in advance!

If you’re returning false from the validateLoginAttempt, it should be logging the user out. Perhaps you need to pair it with a Meteor.onLogout function running in the client to redirect the user to the login modal on the logout event.

relevant docs: Accounts (multi-server) | Meteor API Docs

1 Like

Thanks for your comment. I suspect there’s some other code that overrides that behavior but I’m not sure where to look for (please note that I’m trying to fix a former employees frontend code and I’m still learning frontend).

It might be in the routes.js file - there’s one likely candidate in a code block that redirects a lot of calls to home “/“ to a different route. Also need to check if it actually enters any other part of FlowRouter instead of going to the Accounts modal sign-in

1 Like

If you type Meteor.userId() in the browser console after the user should be logged out, does it come back as null? If so, the user is logged out and it is just a client-side routing issue, in which case, yes, you might have to dig through the FlowRouter routes and global triggers.

If you add something like this in the client side code, assuming there is no other weirdness going on, it should work.

Meteor.onLogout(function(){
    FlowRouter.go('login'); 
});

hope this helps!

Thanks for your comment!

Yes, as you can see in my above post the options.user is undefined, so no valid Meteor.userId() either.

I’d like to try this out but I’m not sure where I should place this piece of code (in the client part of the frontend app obviously but where exactly?)

It should work if you place it in any js file in the top level client folder.

I’m getting Uncaught TypeError: Meteor.onLogout is not a function no matter where I put it in the top level client folder, also when I put it in the file where I have my Accounts.onLogout.

I’ve also tried to find documentation about this (including using ChatGPT) but it says this isn’t an official Meteor documented feature.

Ack, sorry… Accounts.onLogout