Search code examples
node.jswindowsfeathers-authentication

"message": "Invalid login", "code": 401 for @feathersjs/authentication-local in windows while not in linux or mac


When I pulled working code of my project which was working fine in Mac, was giving me this error when authenticating in windows

Error

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

}

post request

{

    "strategy": "local",
      "username": "demo",
      "password": "demo"

}

default.json

 "authentication": {
    "entity": "user",
    "service": "users",
    "secret": "2wVrC38R9sUb6Cjhuhoir3oate0=",
    "authStrategies": [
      "jwt",
      "local"
    ],
    "jwtOptions": {
      "header": {
        "type": "access"
      },
      "audience": "https://yourdomain.com",
      "issuer": "feathers",
      "algorithm": "HS256",
      "expiresIn": "1d"
    },
    "local": {
      "usernameField": "username",
      "passwordField": "password"
    }

},

So strategy local was not at all working


Solution

  • From documentation feathers doc

    "Important: If you want to set the value of usernameField to username in your configuration file under Windows, the value has to be escaped as \\username (otherwise the username environment variable will be used)"

    thus the code change requires in default.json is

      "local": {
      "usernameField": "\\username",
      "passwordField": "password"
       }