0

In my app I have an admin area, this area also has some admin-client MiniMongo that goes with it. So the admin is subscribing to a publication, then this publication puts data from several collections on this admin-client MiniMongo collection.

The access to the subscription is restricted, and so is the publication. But I noticed that the collection still registers for every user, though (I believe) it is being populated with data only when an admin logs in.

Still I would like to know if I can create the collection only when an admin logs in and not before?

Now the code is being run on app startup.

Right now I have it like this:

export const AdminData = new Mongo.Collection("admin_data");

I also tried this, but it doesn't work:

let AdminData;
if(Roles.userIsInRole(Meteor.userId(), 'admin'){
  AdminData = new Mongo.Collection("admin_data");
}

export default AdminData;

If it make a difference this is my project structure

client/
server/
imports/
--api/
----admin/
------client/
--------adminData.js (the above file)
------server/
--------publication.js
--startup/
----client/
----both/
----server/
--ui/
----adminArea/
------adminComponent.jsx (the collection is only imported here)
U Rogel
  • 1,893
  • 15
  • 30

1 Answers1

1

You should create the collection on the server. (move adminData.js besides publication.js). Also you should check security in the publication itself. Meteor.userId() will only work in meteor methods on the server and you will have an error if you leave it there

On the client your adminComponent needs to subscribe to the server publication to have access to the collection's data. To do so you'll need to wrap your component in something like react-komposer

Hope this helps

tuxonator
  • 66
  • 2