meteor-useraccounts / core

Meteor sign up and sign in templates' core functionalities
http://useraccounts.meteor.com/
MIT License
529 stars 278 forks source link

Redirect after Login/Register - Hook not working? (code attached) #729

Open ankitv89 opened 7 years ago

ankitv89 commented 7 years ago

I tried using hooks to redirect to dashboard template after login but this doesn't seem to work. Can anyone help me, on what is wrong in the following code?

onSubmitHook: function(error, state){
         console.log('called');

         console.log(state);
         if (!error) {
             if (state === "signIn") {

                 Router.go('/dashboard');

             if (state === "signUp") {
                 Router.go('/dashboard');
             }
         }
     },
MichaelJCole commented 7 years ago

I have some similar code that works on Meteor 1.4

// lib/AccountsTemplates.js
AccountsTemplates.configure({
  sendVerificationEmail: true,

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

  // Privacy Policy and Terms of Use
  privacyUrl: Meteor.settings.public.privacyPolicy,
  termsUrl: Meteor.settings.public.termsOfService,

  // Texts
  texts: {
     // ...
  },
  // Behavior
  confirmPassword: false,
  enablePasswordChange: true,
  forbidClientAccountCreation: false,
  overrideLoginErrors: true,
  lowercaseUsername: false,
  focusFirstInput: true,

  // Appearance
  showAddRemoveServices: false,
  showForgotPasswordLink: true,
  showPlaceholders: true,
  showLabels: true,
  showResendVerificationEmailLink: false,

  // Client-side Validation
  continuousValidation: false,
  negativeFeedback: false,
  negativeValidation: true,
  positiveValidation: true,
  positiveFeedback: true,
  showValidating: true,

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