Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect not fired on resetPwd? #20

Open
MichaelJCole opened this issue Dec 11, 2016 · 2 comments
Open

Redirect not fired on resetPwd? #20

MichaelJCole opened this issue Dec 11, 2016 · 2 comments

Comments

@MichaelJCole
Copy link

MichaelJCole commented Dec 11, 2016

Hi, resetPwd's redirect isn't firing for me. I've got this code:


AccountsTemplates.configure({
  sendVerificationEmail: true,

  // ,,,

  // Redirects
  homeRoutePath: '/',
  defaultLayout: 'main',

  onLogoutHook: function() {
    // Note: set this hook to override default behavior, even if there's nothing to do.
    Router.go('signIn');
  },
  onSubmitHook: function(error, state) {
    console.log('onSubmitHook', error, state);
    if (error) {
      return sweetAlert({
        title: 'An Error Occured:',
        text: error.reason,
        confirmButtonText: 'Ok, snap!',
        type: 'error',
      });
    }
    switch(state) {
      case 'forgotPwd':
        return sweetAlert({
          title: 'Password Reset Sent!',
          text: 'Check your email inbox for a link to reset your password.',
          type: 'info',
        });
      case 'changePwd':
        return sweetAlert({
          title: 'Password Changed!',
          text: 'Your password has been updated.',
          type: 'success',
        });
      case 'verifyEmail':
        return sweetAlert({
          title: 'Password Changed!',
          text: 'Your password has been updated.',
          type: 'success',
        });
    }
  }
});

AccountsTemplates.configureRoute('forgotPwd', {
  redirect: function() {
    console.log('forgotPwd redirect');
    // Message happens in onSubmitHook.  This only happens if on route.
    Router.go('home');
  }
});
AccountsTemplates.configureRoute('resetPwd', {
  redirect: function() {
    console.log('resetPwd redirect');
    // Message happens in onSubmitHook.  This only happens if on route.
    Router.go('home');
  }
});

When I do a password reset, it logs this:

onSubmitHook undefined forgotPwd
app.js:11126 forgotPwd redirect

Email opens new link. Notice redirect never fires:

onSubmitHook undefined resetPwd

Which is fine, I can put a redirect in the onSubmitHook. But seems like it's missing from the api. Did I miss something?

I just want a success message and to go 'home'. What's the simplest way?

@rajpa
Copy link

rajpa commented Jan 6, 2017

@MichaelJCole I have a similar problem...

var mySubmitFunc = function(error, state){
if (!error) {
if (state === "signIn") {
// Successfully logged in
// ...
console.log("signin : " + Meteor.user().username);
if (!Meteor.user().profile.mob) {
console.log("setting mob for : " + Meteor.user().username);
Meteor.users.update({_id: Meteor.userId()}, {$set : {"profile.mob": 1234}});
Meteor.users.update({_id: Meteor.userId()}, {$set : {"profile.verified": false}});
}
console.log("to verify phone...");
Router.go("/verifyPhone");
return;
}
if (state === "signUp") {
// Successfully registered
// ...
}
}
};

the router.go works but onSubmitHook works right after and redirects to "/".

Any help on this please?

cheers
rajpa

@MichaelJCole
Copy link
Author

MichaelJCole commented Jan 6, 2017

Hi @rajpa

You can use backticks to make your code more readible. On a US keyboard, it's the key to the left of 1.

just surround the code with three `s  before and three after.

I can't really speak to your code, but this is what I have:

AccountsTemplates.configure({
  // ,,,
  onSubmitHook: function(err, state) {},
  onLogoutHook: function() {
    // When user logs out, take them to logout page
    Meteor.setTimeout(function() {
      if (!Meteor.user()) {
        Router.go('home');
      }
    }, 100);
  },
  postSignUpHook: function(userId, info) {
    if (!info || !info.profile || !info.profile.name) return;
    Meteor.users.update(userId, {
      $set: {
        name: info.profile.name
      }
    });
  },
});
AccountsTemplates.configureRoute('signUp', {
  name: 'atSignUp',
  path: '/private-sign-up',
  template: 'mySignUp',
  redirect: '/',
});
AccountsTemplates.configureRoute('signIn', {
  name: 'atSignIn',
  template: 'mySignIn',
  redirect: '/',
});

Maybe that will help? There is a postSignUpHook you may be interested in...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants