Redirect to page after creating user?


#1

I would like to send every newly-created user to a welcome page. I’m aware of Accounts.onCreateUser, but since this is a server-only method, I’m not sure how to fire something like it on the client side. I’m thinking ultimately that the correct solution would include a Router.go(’/welcome/’).

I’m using Flow Router, accounts-password, and ian:accounts-ui-bootstrap-3.

Is there a way to do this?


#2

hey man, this is pretty straightforward, something like this works using Flow Router, in your template event where you create the user, simply add a callback which if successful will re-direct the user to the next page


 Accounts.createUser({email: email, password : password}, function(err){
        if (!err) {
           FlowRouter.go('templateName'); // or go(url)
        }
      });

#3

Where I’m tripping up, is that I’m using the accounts-ui-bootstrap-3 package, so I didn’t write any template events. It’s all being taken care of by the package and the {{> loginButtons}}.

Maybe I need to write custom form fields and events in order to execute on this?

Thanks for your tips!


#4

Damn, I tried to lookup and see if there was a way for you but I couldnt find any client side hook for after creating a user with that package.

A bit of a hacky option is to use the following code under the onCreated hook function for your login / register template

Template.templateName.onCreated(function(){
this.autorun(() => {
if (Meteor.userId()) {
FlowRouter.go('templateName')
}
 });
});

Sorry not sure how to indent my code properly here, tab not working.