Accounts.onLogin with IronRouter

I am trying to redirect the user to the page after login. Trying to use Router.go from the Accounts.onLogin callback:

Accounts.onLogin () -> Router.go('users.new') 

When I try to do this on the server, I get TypeError: Object [object Object] has no method 'go'

On the client, I get Accounts.onLogin undefined

+5
source share
1 answer

You have a problem here:

Accounts.onLogin is undefined on the client because it is a server-only API.

UPDATE 06/15/2015:, this is no longer the case. Accounts.onLogin now also available on the client.

Router.go is undefined on the server, because redirection with iron: router is a client API.

If you use {{> loginButtons}} , you can try this workaround for the client:

 Tracker.autorun(function(){ if(Meteor.user()){ // login handler Router.go("users.new"); } else{ // logout handler } }); 

If you use a custom login form with Meteor.loginWithSomething , you can do the redirection in the login method callback.

+1
source

Source: https://habr.com/ru/post/1203911/


All Articles