Skip to content

Instantly share code, notes, and snippets.

@jim-at-jibba
Last active June 28, 2017 16:37
Show Gist options
  • Save jim-at-jibba/31f48acbeab17efa5797f38ce5112eb7 to your computer and use it in GitHub Desktop.
Save jim-at-jibba/31f48acbeab17efa5797f38ce5112eb7 to your computer and use it in GitHub Desktop.
Example of authenticated routes with restivus and jsonroutes in meteor
import { Restivus } from 'meteor/nimble:restivus';
import { JsonRoutes } from 'meteor/simple:json-routes';
import { Meteor } from 'meteor/meteor';
import YourCollection from '../your-collection';
JsonRoutes.Middleware.use(
'/api/yourCollection',
JsonRoutes.Middleware.parseBearerToken
);
const Api = new Restivus({
useDefaultAuth: false,
auth: {
user() {
const authToken = this.request.authToken;
const user = Meteor.users.findOne({
'profile.token': authToken,
});
return {
user,
};
},
},
});
Api.addCollection(YourCollection, {
// TODO: remove all requests methods except post
excludedEndpoints: ['getAll', 'put', 'delete'],
routeOptions: {
authRequired: true,
},
endpoints: {
post: {
action() {
// logic here
}
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment