meteor-useraccounts / flow-routing

Useraccounts packages add-on for integration with Flow Router and Blaze Layout.
https://atmospherejs.com/useraccounts/flow-routing
MIT License
72 stars 50 forks source link

Register Link 'broken' after login when using AccountsTemplates.ensureSignedIn #52

Open zcrowe opened 7 years ago

zcrowe commented 7 years ago

Hello!

I have a route setup as follows:

FlowRouter.route('/', {
  triggersEnter: [AccountsTemplates.ensureSignedIn],
  name: 'home',
  action(params, queryParams) {
    BlazeLayout.render('dashboard', {main: 'deviceList'});
  },
});

Which redirect to /login-in:

AccountsTemplates.configureRoute('signIn', {
  name: 'login',
  path: '/login'
});

If the 'Register' link is clicked, the register form works, and does allow the user to login. I've noticed the URL does not change to /sign-up as expected. Registering does 'work' but the notification confirming registration and to check their email to confirm is only displayed for a split second before they are sent back to the signup form.

Is this a bug or is my accounts templates setup wrong?

Here it is in case it helps :)

// Documentation: https://github.com/meteor-useraccounts/core/blob/master/Guide.md
AccountsTemplates.configure({
  defaultLayout: 'auth',
  defaultContentRegion: 'main',
  defaultLayoutRegions: {},

  // Behavior
  confirmPassword: true,
  enablePasswordChange: true,
  sendVerificationEmail: true,
  // WARNING - see docs, this may not work with federated logins
  enforceEmailVerification: true,
  focusFirstInput: true,

  // Appearance
  showForgotPasswordLink: true,
  showResendVerificationEmailLink: true,

  // Client-side Validation
  continuousValidation: true,

  // Redirects
  //homeRoutePath: 'login',

  // Hooks
  onLogoutHook: function () {
    FlowRouter.go('login');
  },

  // Text
  texts: {
    title: {
      resendVerificationEmail: "Enter you email below and we'll resend your verification email",
    }
  }
});

AccountsTemplates.addField({
  _id: 'username',
  'displayName': 'Display Name',
  type: 'text',
  placeholder: {
      signUp: "Suitable for public display, must be unique!"
  },
  required: true,
  minLength: 3,
  re: /^[a-zA-Z0-9]+$/,
  errStr: 'Username is required',
});

//Documentation: https://github.com/meteor-useraccounts/flow-routing
AccountsTemplates.configureRoute('signIn', {
  name: 'login',
  path: '/login'
});

AccountsTemplates.configureRoute('signUp');

AccountsTemplates.configureRoute('forgotPwd');

AccountsTemplates.configureRoute('resetPwd', {
  name: 'resetPwd',
  path: '/reset-password'
});

AccountsTemplates.configureRoute('changePwd', {
  name: 'changePwd',
  path: '/settings',
  layoutTemplate: 'dashboard',
  contentRegion: 'main',
  layoutRegions: {},
  homeRoutePath: 'home',
});

AccountsTemplates.configureRoute('verifyEmail', {
  name: 'verifyEmail',
  path: '/verify-email',
  layoutTemplate: 'dashboard',
  contentRegion: 'main',
  layoutRegions: {},
  homeRoutePath: 'home',
});
zcrowe commented 7 years ago

Any one got any insights they can offer?

roelvan commented 6 years ago

got this too +1

roelvan commented 6 years ago

This dirty hack should fix the problem @zcrowe: Create a file eg. at-form.js:

Template.atForm.onCreated(function() {
  const template = this;
  template.autorun(() => {
    if (AccountsTemplates.getState() === 'signUp') {
      FlowRouter.go('/register') // your registration url path
    }
  });
});