How to get Meteor.user() to return on the server side?

前端 未结 4 1293
名媛妹妹
名媛妹妹 2020-12-13 06:50

in a file called /server/main.js (in order to ensure it is loaded last).

console.dir(Meteor.user());

Throws:

Error: Meteor.         


        
4条回答
  •  無奈伤痛
    2020-12-13 07:32

    I recently wrote a blog post describing solution to this: https://blog.hagmajer.com/server-side-routing-with-authentication-in-meteor-6625ed832a94.

    You basically need to set up a server route using a https://atmospherejs.com/mhagmajer/server-router package and you can get current user with this.userId just like with Meteor methods.

提交回复
热议问题