简体   繁体   中英

meteor posts by current user

I am following the tutorial on the simple posts app and make it to work(that you put in your name and message then submit , and meteor will update it to messages template ). Now I want to extend it to have user sign in and messages will only show the posts by the current user . I got the sign in to work but not sure how to change the message code so that it work something like this:

{{#if currentuser}}
   {{#each messages}}
        {{posts by currentuser}}
    {{/each}}  
{{/if}}

How can I do that?

I think the correct approach to this is to do this server side .

What you want to do is return only the posts data for the current user who is logged in, because otherwise you are proposing to get all the posts and filter them in your client. That is going to be slow, and why return results that you do not need?

One of the strengths of Meteor as a development platform is that it abstracts a lot of the differences between client and server side code. But this is an area where you should not be relying on the general abstraction.

This question should show you the ropes of how to filter out your server query to do this:

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

We could offer more help. But you didn't provide that part that we need in your question. If you have trouble working this out, then perhaps another question then?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM