shaunthomas999
shaunthomas999

Reputation: 5844

Meteor not able to use Session in server side with coffeescript

I am using Meteor with coffeescript. I have a file named methods.coffee under lib folder inside Meteor project. A snippet of the file content is as follows:

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

When I try to call the method authenticateUser, an error is thrown saying that Session is not defined. Is it not possible to set to Session inside a Meteor method? If possible, how can I do that? Thanks in advance.

Upvotes: 0

Views: 139

Answers (1)

Peppe L-G
Peppe L-G

Reputation: 8345

Session is only available on the client. The session value you want to use on the server needs to be passed as an argument in the method call.

Upvotes: 1

Related Questions