I’m trying to implement an invite feature in my Meteor app. I fire off Accounts.sendEnrollmentEmail(userId, email)
which then sends an email to an invited user with a link in the form of http://localhost:3000/#/enroll-account/4eoe7JmrIdFh6vyz00_njU6WZE-Fc5RYFOIbRKP4YSf
.
My desired behaviour would be that once the user clicks the link, they are automatically signed in (and they can set their new password or maybe I can redirect them to a page of my choosing). However, once they click the link, they are routed to my 'home'
page. I want them to be routed and signed into my 'main'
page. Once I removed the FlowRouter.triggers.enter
call below it works, but then the main
page is open to all unsigned in users. How can I get the user to be signed in and not reroute them based on my trigger. I’m guessing the user is being redirected before they are being signed in…how can I fix this?
function ensureSignedIn(context, redirect) {
if (!Meteor.userId())
redirect("/home");
}
FlowRouter.triggers.enter([ensureSignedIn],
{except:
[
'home', 'sign-in',
'create-org', 'create-username', 'create-invite', 'create-confirm',
'enroll-account',
]
});
FlowRouter.route('/', {
name: "main",
action() {
ReactLayout.render(App, {content: <MainPage />})
}
});
FlowRouter.route('/#/enroll-account/:token', {
name: 'enroll-account',
triggersEnter: [checkAlreadySignedIn],
action() {
Utils.log('enroll-account route');
}
})