Meteor无法在服务器端使用带有coffeescript的Session

时间:2015-01-03 16:28:49

标签: meteor

我正在使用Meteor和coffeescript。我在Meteor项目中的lib文件夹下有一个名为methods.coffee的文件。文件内容的片段如下:

if Meteor.isServer
    Meteor.methods
        authenticateUser: (email, password) ->
            customerCursor = Customers.find({"email": email, "password": password})
            if customerCursor.count()
                console.log "Authentication successful for #{email}"
                customerArray = customerCursor.fetch()
                Session.set("CID", customerArray[0].CID)
                console.log "CustomerId #{Session.get("CID")} stored in session"
                return true
            else
                console.log "Authentication failed for #{email}"
                return false

当我尝试调用方法authenticateUser时,会抛出一个错误,说明没有定义Session。是否无法在Meteor方法中设置Session?如果可能的话,我该怎么做?提前谢谢。

1 个答案:

答案 0 :(得分:1)

Session仅适用于客户端。您要在服务器上使用的会话值需要作为方法调用中的参数传递。

相关问题