简体   繁体   中英

Feathers authentication.create throws 401 not authenticated error

// code

app.use('/login', {
  async create(data, params) {
    data.strategy = 'local';
    return authentication.create(data, params);
  }
});

// config

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

I am using authentication.create method in my login API, I am getting this error response when i try to login

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

// request

curl --location --request POST 'http://localhost:3030/login'
--header 'Content-Type: application/json'
--data-raw '{
"username": "uname",
"password": "123456"
}'

The username and password is correct, this works in my local machine(macOS), it throws error only when i run in a testing environment(ubuntu 20 in AWS EC2). they both point to the same database(mySQL 5) inside a AWS EC2 instance. what is causing the issue?

Mentioned in the authentication configuration options in Windows and with PM2 the username field needs to be escaped since it is also an environment variable:

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

This will no longer be necessary in the upcoming version 5.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM