1
我会感谢我的铁路由器注销重定向代码的一些反馈。铁路由器登录和注册最佳实践
我打算只允许登录用户访问路由其他比登录或注册,并重定向他人登录错误代码。
// routes.js with Router.beforeAction
if (!Meteor.userId()) {
// Get current route
var currentRoute = Router.current().route.getName();
// if the current user is not trying to login or register send to login with error
if (currentRoute = 'register'){
this.layout('login');
this.render('registerview');
} else if (currentRoute = 'login') {
this.layout('login');
this.render('loginview');
} else {
Session.set("errorMessage", "You need to log in to access this page.");
this.redirect('/login');
}
} else {
// otherwise don't hold up the rest of hooks or our route/action function
// from running
this.next();
}
这个工程,但我会很感激一些效率和良好的代码反馈。
此外,我的routes.js文件在/客户端,我知道登录逻辑应发送到服务器方法,但是有任何安全问题的路由文件?
因此,反馈是:将测试定义为函数并以这种方式调用它们。我也在编辑答案。 – StefanL19
shti go editna:D –
喜欢这个?:http://codepen.io/SlartyBArtfast/pen/wGgGMZ – SlartyBartfast