Reputation: 241
I'm trying to set up a mechanism for downloading a PDF file which is available only if a member logs in (restricted access)
So I'm looking on two options:
1) I already have a PDF and would like to add it in public folder but don't know how to restrict the access towards the same (if user logged then access)
2) Have the file on the server and actually make a Meteor.Call from the client to grab the pdf and get it back for download.
Which option is the simplest to implement and how should I do it. I have been crawling the web for the past day and I just can't figure it out how to implement either...
Upvotes: 0
Views: 99
Reputation: 9876
Store your items in Mongo as a collection using GridFS (see this answer for an example, it's no more difficult than inserting to any other collection really btw). Then you can control access to the file collection as with any other collection, by publishing correctly:
Meteor.publish('fileCollection', function(){
if (this.userId) return fileCollection.find();
});
By checking if the user has an ID, we'll know if they're a logged in user. Test the ID further for specific user interactions, add an array field of user IDs that have access to files (then do a .find() for collections where the users ID is in that array in your .publish()) or publish your file to all users as above just by checking if they have any non-empty ID.
Upvotes: 1