Maximus S
Maximus S

Reputation: 11095

Meteor server-side redirection when new user is created

I want to redirect when a new user account has been created.

Accounts.onCreateUser(function(options, user) {
// what to do?
})

I am using iron:router but Router.go() doesn't work because it's only for the client. Iron Router is said to support server-side redirection but in this case, I am not sure how to apply it.

Upvotes: 3

Views: 810

Answers (1)

Jon
Jon

Reputation: 493

You can use your own method in client code that calls a server method which will call Accounts.createUser. If the method succeeds you can then perform a redirect. e.g

       //client method
        Meteor.call('createUser', userObj, function(err,data) {
          if (err) {
          //account creation failed
          } else {
          //success, redirect
          Router.go('routeName');
        }
        });


        //server code
        Meteor.methods({
          createUser: function(user) {
            //account creation
            Accounts.createUser(user);
          }
        });

Upvotes: 1

Related Questions