【问题标题】:Feathers authentication.create throws 401 not authenticated errorFeathers authentication.create 抛出 401 not authenticated 错误
【发布时间】:2021-06-18 19:15:17
【问题描述】:

// 代码

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

// 配置

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

我在登录 API 中使用 authentication.create 方法,当我尝试登录时收到此错误响应

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

// 请求

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

用户名和密码正确,这适用于我的本地机器(macOS),仅当我在测试环境(AWS EC2 中的 ubuntu 20)中运行时才会引发错误。它们都指向 AWS EC2 实例中的同一个数据库(mySQL 5)。是什么导致了这个问题?

【问题讨论】:

    标签: node.js feathersjs feathers-authentication feathers-service


    【解决方案1】:

    在 Windows 和 PM2 中的 authentication configuration options 中提到,username 字段需要转义,因为它也是一个环境变量:

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

    在即将发布的第 5 版中将不再需要此功能。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-17
      • 1970-01-01
      • 2015-08-30
      • 2014-07-08
      • 1970-01-01
      • 2018-03-01
      相关资源
      最近更新 更多