Last active
June 28, 2017 16:37
-
-
Save jim-at-jibba/31f48acbeab17efa5797f38ce5112eb7 to your computer and use it in GitHub Desktop.
Example of authenticated routes with restivus and jsonroutes in meteor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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