nicolaslopezj / roles

The most advanced roles package for meteor
MIT License
87 stars 13 forks source link

Questions about Meteor.user().roles and package associated collections #19

Open PolGuixe opened 8 years ago

PolGuixe commented 8 years ago

As far as I know Meteor.users just publishes _id, profile and emails. But with this package, I also see that the roles field is published. Can you confirm it?

PolGuixe commented 8 years ago

I see that it also generates 2 collections:

-roles -nicoloaslopez_roles_keys

How are they used?

nicolaslopezj commented 8 years ago

The roles field is published but not automatically https://github.com/nicolaslopezj/roles/blob/master/roles_server.js#L4

The roles collection is the old collection, it's a collection that is not in use right now.

nicoloaslopez_roles_keys is a functionality that is not yet documented. It allows you to generate a key in the client and then in the server take the key and get the userId. This is only useful when using server side routes. For example: you want to download a file with permissions. First you request the key in the client, then send the user to the server side url with the key in the parameters and then you can fetch the userId with the key.

Request a key:

Roles.keys.request(Meteor.userId())

Fetch the key server side:

const key = this.request.params.key
Roles.keys.getUserId(key)

You can see a real example here

https://github.com/nicolaslopezj/orion-exporter/blob/master/exporter_client.js#L33 https://github.com/nicolaslopezj/orion-exporter/blob/master/exporter_server.js#L5