kahmali / meteor-restivus

REST APIs for the Best of Us! - A Meteor 0.9+ package for building REST APIs https://atmospherejs.com/nimble/restivus
MIT License
544 stars 116 forks source link

Add 'authOptional' #173

Closed VansonLeung closed 7 years ago

VansonLeung commented 8 years ago

Add 'authOptional' to optionally require login auth, if user is logged in, then endpoint 'this.user' & 'this.userId' exists. If not logged in / auth error, endpoint 'this.user' & 'this.userId' will be undefined. User is still accessible to the API but as a guest then. This allows more granular control over custom API authentication. e.g. When querying shops by Shops.find(), Members can know whether they have favorited a Shop by Favorites.find({shop_id: doc._id, user_id: self.userId}).count > 0 in collection.transform, while guests will just show shop list, as userId is undefined for guests.

kahmali commented 8 years ago

Looks good. Just need to make that update to the docs I mentioned in the line comments, and add tests to verify the functionality. Try to give solid test coverage, or you'll have to resubmit again (so make sure you test it alongside auth requirement, as well as by itself).

VansonLeung commented 8 years ago

Thank you, I will try to set the tests too

kahmali commented 7 years ago

I'm closing this as it's a year old and appears to have gone stale. I'm happy to reopen it if anyone needs this feature and would like to finish up the PR.