Is there a hook for an auto-login after an app reload?

My app is internationalized using the tap:i18n package. I’ve also set-up a user preference, so the app will show up in the correct language if the user logs in. I placed this logic in an onSubmit() hook of the useraccounts package.

This works if the user logs in via the login form, but it doesn’t work if the user is logged in transparently, using a login token. So after a hot-code reload, for instance, my app always shows up in its default language, i.e. English.

I’ve also tried the Accounts.onLogin() hook, but this behaves just the same. Of course, I could use a global Tracker.autorun() and check for Meteor.userId(), but this seems like a hack to me. And it also doesn’t work reliably, because the user profile subscription is not always available at this time.

Is there any hook that fires right after the user is (transparently) logged in?

Have you thought about creating your own login handler using Accounts.registerLoginHandler? That should give you complete control over the entire login process, allowing you to add in any hooks you want to. I remember MeteorHacks having a good post outlining this … yes, got it - Extending Meteor Accounts.

Thanks for that tip!

I’m pretty sure you can use [DDP].onReconnect to accomplish something similar

What exactly do you mean by [DDP]?

It’s like a connection to a meteor server. Some documentation here. I think this particular line is kind of what you are after:

onReconnect Set this to a function to be called as the first step of reconnecting. This function can call methods which will be executed before any other outstanding methods. For example, this can be used to re-establish the appropriate authentication context on the new connection.