Question

I'm using meteor with iron-router and I want the app to automatically go to the 'dashboard' template when a user successfully signs in. How do I do this? Here is my code:

javascript:

// Sign In Template
Template.signIn.events({
    'submit #signInForm': function(e, t) {
        e.preventDefault();

        var signInForm = $(e.currentTarget),
            email = trimInput(signInForm.find('.email').val().toLowerCase()),
            password = signInForm.find('.password').val();

        if (isNotEmpty(email) && isEmail(email) && isNotEmpty(password) && isValidPassword(password)) {
            Meteor.loginWithPassword(email, password, function(err) {
                if (err) {
                    Session.set('alert', 'We\'re sorry but these credentials are not valid.');
                } else {
                    Sesson.set('alert', 'Welcome back New Meteorite!');


                }
            });
        }
        return false;
    },
});
Was it helpful?

Solution

The Accounts Entry package from atmosphere can help you do that and more in a visually appealing and seamless way.

As the documentation describes with an example:

Meteor.startup(function() {
  return AccountsEntry.config({
    logo: 'logo.png',
    privacyUrl: '/privacy-policy',
    termsUrl: '/terms-of-use',
    homeRoute: '/',
    dashboardRoute: '/dashboard', // you have an autoconfigured dashboard route
    profileRoute: 'profile',
    passwordSignupFields: 'EMAIL_ONLY',
    showSignupCode: true
  });
});

And in order to protect your routes, you simply configure:

Route.map(function() {
  this.route('createPayment', {
    path: '/create/payment',
    before: function() {
      return AccountsEntry.signInRequired(this);
    }
  });
});

OTHER TIPS

In the success case from your loginWithPassword, you can just call:

Router.go('dashboard');

This is assuming you have a route named dashboard. For example:

Router.map(function () {
  this.route('dashboard', {
    path: '/user/dashboard',
    template: 'userDashboard'
  });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top