需要在 feathersjs 中添加多个用户名字段



我是feathersjs的新手,我正在使用它构建后端服务器,需要添加2种本地身份验证方式,通过电子邮件或移动设备 我已经将新的本地添加到config/default.json中,如下所示

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

这是我的身份验证.js文件

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());
};

src/authentication

但是当我使用带有以下正文的邮递员向身份验证端点发送 post 请求时

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

响应即将到来

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

任何想法 ?

如果要允许通过authenticate终结点进行身份验证,还必须将该策略添加到config/default.json中的 authStrategies 配置设置中(羽毛聊天示例(:

{
"authentication": {    
// ...
"authStrategies": [
"jwt",
"local",
"local-mobile",
]
}
// ...
}

最新更新