Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authenticate shows error: No auth token #667

Closed
Elminday opened this Issue Apr 18, 2018 · 4 comments

Comments

Projects
None yet
2 participants
@Elminday
Copy link

Elminday commented Apr 18, 2018

Problem

Calling:
service('users').create({ username, email, password })
Shows error:
No auth token

The error is from: authenticate(['jwt', 'local']) in `authentication create before hook.

Deeper callstack:
/node_modules/@feathersjs/authentication-jwt/node_modules/passport-jwt/lib/strategy.js

Line 93:
var token = self._jwtFromRequest(req) undefined

System configuration

   "@feathersjs/authentication": "^2.1.3",
    "@feathersjs/authentication-client": "^1.0.2",
    "@feathersjs/authentication-jwt": "^2.0.0",
    "@feathersjs/authentication-local": "^1.1.1",
    "@feathersjs/configuration": "^1.0.2",
    "@feathersjs/express": "^1.2.1",
    "@feathersjs/feathers": "^3.1.4",
    "@feathersjs/socketio": "^3.2.0",
    "@feathersjs/socketio-client": "^1.1.0",
    "feathers-authentication-hooks": "^0.1.7",
    "feathers-authentication-management": "^2.0.0",
    "feathers-hooks-common": "^3.6.1",
    "feathers-memory": "^2.1.1",

Operating System: Linux

Browser: Chrome

Authentication service before hooks:

create: [
    authenticate(['jwt', 'local'])
  ],
  remove: [
    authenticate('jwt')
  ]

User service before hooks:

all: [],
  find: [
    auth.authenticate(['jwt', 'local']),
  ],
  get: [
    auth.authenticate(['jwt', 'local']),
  ],
  create: [
      auth.authenticate(['jwt', 'local']),
      setUUID(),
    ),
  ],
  update: [
    disallow('external'),
  ],
  patch: [
    auth.authenticate(['jwt', 'local']),
  ],
  remove: [
    auth.authenticate(['jwt', 'local']),
  ]

Server app.js

const app = express(feathers());
app
 .configure(configuration())
 .configure(express.rest())
 .configure(socketio(io => io.set('origins', '*:*')))
 .use(compression())
 .options('*', cors())
 .use(cors({ origin: true }))
 .use(express.json())
 .use(express.urlencoded({ extended: true }))
 .configure(auth({ secret: 'SECRET' }))
 .configure(local())
 .configure(jwt())
 .use('/users', memory())
 .use(cookieParser())
 .use(express.errorHandler())

Client-side app where I also use authenticate

import feathers from '@feathersjs/feathers';
import auth from '@feathersjs/authentication-client';
import socket from '@feathersjs/socketio-client';
import io from 'socket.io-client';

let instance = false;
const config = global.CONFIG;
const storage = (global.TYPE === 'CLIENT') ? window.localStorage : null;
const uri = ['http://', config.io.host, ':', config.io.port].join('');
export function app() {
  if (instance) return instance;
  instance = feathers()
    .configure(socket(io(uri)))
    .configure(auth({ storage }));
  return instance;
}
@daffl

This comment has been minimized.

Copy link
Member

daffl commented Apr 18, 2018

If you want users to sign up, the create method for users should not have an auth.authenticate

@Elminday

This comment has been minimized.

Copy link
Author

Elminday commented Apr 18, 2018

Still the same error.

@daffl

This comment has been minimized.

Copy link
Member

daffl commented Apr 19, 2018

If that error is happening calling app.authenticate() on the client, it's fine since you'll still be able to sign up as a user showing the signup page in the error handler. See the one of the frontends in feathers-chat for reference.

@Elminday

This comment has been minimized.

Copy link
Author

Elminday commented Apr 19, 2018

Found the problem.

Was doing this:

  this.app.hooks({ 
    before: require(dir + '/hooks.before.js').default, 
    after: require(dir + '/hooks.after.js').default  
  });

Instead of this:

const service = this.app.service(ServiceConfig.namespace);

  service.hooks({ 
    before: require(dir + '/hooks.before.js').default, 
    after: require(dir + '/hooks.after.js').default  
  });

In my autoloader of services.

@Elminday Elminday closed this Apr 19, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.