feathers: Intermittent NotAuthenticated: No auth token

I have a bizarre issue that I can’t find the root cause of and it’s only just manifested itself. The request I’m making to a service then has a few hooks that perform updates on other services but every so often during the various updates I get the error NotAuthenticated: No auth token. Restarting the feathers app seems to clear it sometimes and then the exact same request will work.

I’m assuming that somehow on occasion my headers are getting removed but I have no idea what would cause that to happen, and I’ve checked to make sure the header is being sent every time.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 26 (8 by maintainers)

Most upvoted comments

@jamesholcomb. Thanks, that works for me as well. Looked up the documentation and it makes sense, kind off. If it’s optional though as the documentation says it is, this should be considered a bug.

Try adding provider: undefined to your populate schema hook argument. That fixed my particular issue.

Thank you. I followed your advice and https://docs.feathersjs.com/api/express.html#custom-service-middleware and it is now working correctly. I created a custom service with a dummy class so that I can get a place for the hook to get the data I need then added a middleware that runs after the service. What I was trying before was to get the data into the middleware function directly. May be that is not possible? Sorry for posting all this code here but I searched for a long time and couldn’t find a solution so I thought may be this solution may help somebody in the future/ Thanks again.

//dummy class for 'custom' download service
class Service {
  constructor (options) {
    this.options = options || {};
  }
  get (id, params) { 
    return Promise.resolve({id});
  }
}

module.exports = function (options) {
  return new Service(options);
};
module.exports.Service = Service;
//hooks for download service 
const { authenticate } = require('feathers-authentication').hooks;
module.exports = {
  before: {
    all: [ authenticate('jwt') ]
  },
  after: {
    get: [
      function getdownloadfileinfo (hook) {
        return hook.app.service('uploads').get(hook.result.id).then(fileinfo=> {
          hook.result = fileinfo;
          return hook;
        });
      }  
    ]
  }
// Initializes the `download` service on path `/download
const createService = require('./download.class.js');
const hooks = require('./download.hooks');
const filters = require('./download.filters');
var path = require('path');
var fs = require('fs');

module.exports = function () {
  const app = this;
  const options = {
    name: 'download',
  };
  const filestore = app.get('filestore');
  app.use('/download', 
    createService(options),
    function(req,res) {   // middleware function here <--
      const a = res.data;
      const fileondisk = path.join(filestore,'' + a._id);
      if(!fs.existsSync(fileondisk)) {
        res.status(404).end();
      } else {
        //console.log('file is there!!!\n\n');
        res.sendFile( fileondisk,
          {
            headers: {
              'Content-Type' : a.mimetype,
              'Content-Disposition' : 'attachment; filename="' + a.filename + '"',
              'Content-Length' : a.filesize
            }
          },function(err){
            if(err) console.log(err);
          }
        );
      }
    }
  );
  const service = app.service('download');
  service.hooks(hooks);
  if (service.filter) {
    service.filter(filters);
  }
};

After upgrading client and server to Buzzard, I am seeing this behavior as well for populate.

For some reason, { provider: ‘socketio’ } is coming in on options.schema even though this particular populate originated out-of-band from an RxJs subscription that processes messages on a queue. Error is ‘No auth token’

Same issue if I initiate the flow via REST.

based on the feathers chat chatwithupload upload works. when you try to download it gives authentication error. stop node and run node and download works.