Compatibility
Compatible with Meteor 2.4
This repository provides versions for the package simple:authenticate-user-by-token that are compatible with latest Meteor. This is necessary because the author is not maintaining package anymore.
Changes
- v1.2.0
api.versionsFromonPackage.onUsewas changed from1.0to2.4.
simple: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});