流星路线&会话 - >如何协调

时间:2016-02-11 16:11:57

标签: meteor iron-router

流星问题:实施真实会话的最佳方式是什么? 我有一个包含统计信息的普通登录页面。那里没有问题。

现在,我希望人们能够使用特定的网址办理登机手续;以后假设他们 点击了http://localhost:3000/checkin/area1

这样的网址

如何协调登录?

我有签到的路线:

Router.route('/checkin/:_id', function () {
  var req = this.request;
  var res = this.response;

  this.userId = 'steve';  //TODO: Need way to pull userId
  if (!this.userId) {
    res.end('Please login first');
  } else {
    //Verify correct area
    //Verify that haven't check before
    var lastCheckin = checkins.find({ user: this.userId, visited: this.params._id });
    if (lastCheckin.count() == 0) {
        //we haven't checkedin yet
        checkins.insert({ user: this.userId, visited: this.params._id, createdAt: new Date() })
        res.end('Checkin '+this.userId+' for '+this.params._id);
    } else {
        console.log('already checked in '+lastCheckin.createdAt);
        res.end(this.userId+' already visited '+this.params._id);
    }
  }
}, {where: 'server'});

我尝试的事情:

  • 持久会话:但这不起作用,因为请求不是来自主页面,所以没有会话变量可以拉动。
  • 在请求中拉出cookie(因为持久会话似乎有1)。原始登录信息似乎没有请求对象,因此我不知道从哪里获取该信息。
  • 其他(差异情况)在路径中显示了Meteor.user(),但软件抱怨它只能在方法中使用。什么可以在路线内使用?

我还能尝试什么?

谢谢你的帮助。

1 个答案:

答案 0 :(得分:0)

好的,我不确定这是否会有所帮助。

如果你在/ myPage上,那么你有一个运行的事件:

Router.go('/yourPage');
Session.set('yourVariable', "yourValue");

您将能够访问/ yourPage(和yourPage的代码)中的会话变量(yourVariable)。