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

Redirect to previous route after successful login not working #16

Closed st3phan closed 8 years ago

st3phan commented 9 years ago

My config for a custom sign-in route:

AccountsTemplates.configureRoute('signIn', {
    name: 'signIn',
    path: 'sign-in',
    template: 'signIn',
    layoutTemplate: 'layout',
    layoutRegions: {},
    contentRegion: 'template',
});

The private route successfully redirects to the custom sign-in template using a trigger:

FlowRouter.route('/private', {
    triggersEnter: [AccountsTemplates.ensureSignedIn],
    name: 'private',
    action: function (params, queryParams) {
        BlazeLayout.render('layout', { template: 'private' });
    }
})

But after a successful login it doesn't redirect back to the '/private' route. This should be default behaviour right? Or am I missing something?

This is my sign-in template:

<template name="signIn">
    <button>Login</button>
</template>
Template.signIn.events({
    'click button': function(e) {
        Meteor.loginWithPassword('foo@bar.com', 'password', function(err) {
            if (err) {
                console.log(err)
            }
        });
    }
});
splendido commented 8 years ago

I think the problem is you're using your custom helper to call Meteor.loginWithPassword. All logic and redirects provided with useraccounts packages happens with its custom helpers: for example these lines are those using a callback to possibly redirects the user somewhere after the login.

If your signIn template only needs to call Meteor.loginWithPassword try to change it to match the original lines.

splendido commented 8 years ago

The thing about providing custom templates is a little more complicated and you can find some discussion about it among the issues of the core repo. For example lets have a look at This comment, but you can also read https://github.com/meteor-useraccounts/core/issues/212.

splendido commented 8 years ago

@st3phan, any update on this?