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.
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);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With