2

I'm new to feathersjs I'm building a backend server using it, and need to add 2 ways of local authentication, by email, or mobile I've already added new local to the config/default.json as the following

"local-mobile": {
      "usernameField": "mobile",
      "passwordField": "password"
    },

here's my authentication.js file

const { AuthenticationService, JWTStrategy } = require('@feathersjs/authentication');
const { LocalStrategy } = require('@feathersjs/authentication-local');
const { expressOauth } = require('@feathersjs/authentication-oauth');

module.exports = app => {
  const authentication = new AuthenticationService(app);

  authentication.register('jwt', new JWTStrategy());
  authentication.register('local', new LocalStrategy());
  authentication.register('local-mobile', new LocalStrategy());

  app.use('/authentication', authentication);
  app.configure(expressOauth());
};

in src/authentication

But when I send a post request to the authentication endpoint using postman with the following body

{
    "strategy":"local-mobile",
    "mobile":".......",
    "password":"........"

}

the response is coming

{
    "name": "NotAuthenticated",
    "message": "Invalid authentication information",
    "code": 401,
    "className": "not-authenticated",
    "errors": {}
}

any Idea ?

Marwan Ze
  • 69
  • 5

1 Answers1

2

If you want to allow authentication through the authenticate endpoint, the strategy also has to be added to the authStrategies configuration setting in your config/default.json (feathers-chat example):

{
  "authentication": {    
    // ...
    "authStrategies": [
      "jwt",
      "local",
      "local-mobile",
    ]
  }
  // ...
}
Daff
  • 43,734
  • 9
  • 106
  • 120
  • @Daff I made this same mistake when adding a strategy just like this. I wonder if there's a way to provide a better error message or diagnostics in this case? It took me some source-level digging to find my oversight. – Joe Oct 01 '19 at 00:41
  • Would be fairly easy to improve the error message in https://github.com/feathersjs/feathers/blob/2707c3331721be6a4a0a943b0fbc118379a1ad2a/packages/authentication/src/core.ts#L219 so an issue or PR to track this would be welcome. – Daff Oct 01 '19 at 03:44
  • PR with a better error message in https://github.com/feathersjs/feathers/pull/1600 – Daff Oct 03 '19 at 20:55