I am building an app in meteor in which one of the pages is visible to user only if the user is logged in. The link to the page is in the navigation header and I want a login dialog to be displayed when the user clicks on the link without logging in. Here is the code for showing the dialog :
<template name="header">
<a href="#" id="createPost">Create Post</a>
</template>
Template.header.events({
"click #createPost": function (evt) {
evt.preventDefault();
if(!Meteor.user()) {
$('#myModal').modal("show"); //bootstrap modal dialog
}else{
Router.go('/createPost');
}
}
}
However, the problem is that Meteor.user() check can easily be bypassed from browser console using Meteor.user = function(){return true;}
I tried checking Meteor.user() in the route and throwing an exception as follows :
Router.route('/createPost', function () {
if (!Meteor.user()) {
throw new Meteor.Error(500, 'You are not logged in.');
}
this.render('newbag');
});
But this check also doesn't work once Meteor.user has been modified in the browser. What is the best way to handle this case and preventing the page from being displayed.