itgenio:authenticate-user-by-token
SimpleRest middleware for validating a Meteor.user's login token
Middleware Name
This middleware can be accessed as:
JsonRoutes.Middleware.authenticateMeteorUserByToken
Request Properties Required
request.authToken- String
- A valid login token for a
Meteor.useraccount (requiresaccounts-base)
Request Properties Modified
request.userId- String
- If the
request.authTokenis found in a user account, sets this to the ID of the authenticated user. Otherwise,null.
Usage
Simply add this layer of middleware after any token parsing middleware, and voila!
For example:
1JsonRoutes.Middleware.use('/auth', JsonRoutes.Middleware.parseBearerToken); 2JsonRoutes.Middleware.use('/auth', JsonRoutes.Middleware.authenticateMeteorUserByToken); 3 4JsonRoutes.add('GET', 'auth/test', function (request, response) { 5 // The authenticated user's ID will be set by this middleware 6 var userId = request.userId; 7});