使用用户名或电子邮件进行身份验证
问题描述:
使用feathers-authentication可以使用可配置的用户名字段对用户进行身份验证。目前,我可以配置身份验证以使用我的用户模型的username
或email
字段,但我想向用户提供选项username
和email
。使用用户名或电子邮件进行身份验证
这样做的最好方法是什么?
答
显然,这是可能的串联身份验证方法,因此解决方案应该是这样的:
app.configure(auth({ secret: 'super secret' }))
.configure(local()) // defaults usernameField to 'email'
.configure(local({ // support username
name: 'local-username',
usernameField: 'username'
}));
一个更完整的例子可以在GitHub上找到:https://github.com/jaredhanson/passport-local/pull/148#issuecomment-261506180