Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meteor server-side redirection when new user is created

Tags:

meteor

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.

like image 751
Maximus S Avatar asked Mar 23 '26 17:03

Maximus S


1 Answers

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);
          }
        });
like image 194
Jon Avatar answered Mar 26 '26 10:03

Jon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!