simple:authenticate-user-by-token

v1.0.0Published 8 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

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.user account (requires accounts-base)

Request Properties Modified

  • request.userId
    • String
    • If the request.authToken is 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});