- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
POST localhost/api/login
使用(正确的)数据 username=test password=test 给出以下内容:
Error: Unknown authentication strategy "[object Object]"
at attempt (/var/www/node_modules/passport/lib/middleware/authenticate.js:166:37)
at authenticate (/var/www/node_modules/passport/lib/middleware/authenticate.js:342:7)
at Layer.handle [as handle_request] (/var/www/node_modules/express/lib/router/layer.js:82:5)
at next (/var/www/node_modules/express/lib/router/route.js:110:13)
at Route.dispatch (/var/www/node_modules/express/lib/router/route.js:91:3)
at Layer.handle [as handle_request] (/var/www/node_modules/express/lib/router/layer.js:82:5)
at /var/www/node_modules/express/lib/router/index.js:267:22
at Function.proto.process_params (/var/www/node_modules/express/lib/router/index.js:321:12)
at next (/var/www/node_modules/express/lib/router/index.js:261:10)
at SessionStrategy.strategy.pass (/var/www/node_modules/passport/lib/middleware/authenticate.js:318:9)
路线:
app.post('/api/login', passport.authenticate(new LocalStrategy(function(username, password, done) {
db.User.findOne({username: username}, function(err, user) {
if (err) return done(err);
if (!user) return done(null, false, { message: 'Username or password incorrect' });
bcrypt.compare(password, user.passHash, function(err, res) {
if (err) return done(err);
if (!res) return done(null, false, { message: 'Username or password incorrect' });
return done(null, user);
})
})
})))
我正在运行 bodyParser,并且我知道它正在从我的注册路线运行。这里发生了什么?我一直在使用http://passportjs.org/guide指南并且已经掌握了基础知识,但是为什么会发生这种情况?
最佳答案
authenticate()
不接受对象,它接受一个包含您之前配置的策略名称的字符串。您的 new LocalStrategy()
被传递给 passport.use()
。
因此,您可以在中间件定义中执行此操作:
passport.use(new LocalStrategy(function(username, password, done) {
db.User.findOne({username: username}, function(err, user) {
if (err)
return done(err);
if (!user)
return done(null, false, { message: 'Username or password incorrect' });
bcrypt.compare(password, user.passHash, function(err, res) {
if (err)
return done(err);
if (!res)
return done(null, false, { message: 'Username or password incorrect' });
return done(null, user);
})
})
}));
然后你为你的路线做这样的事情:
app.post('/api/login',
passport.authenticate('local'),
function(req, res) {
// authentication successful
});
关于node.js - 错误: Unknown authentication strategy "[object Object]",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28311590/
在大多数示例中,策略模式通常适用于压缩算法/编解码器算法,其中这些算法可能具有完全不同的代码。 但是,在我的例子中,我想重构为策略模式的统计算法有 50% 的代码相似或完全相同。我想知道人们如何处理这
git merge选项有什么区别--strategy-option(短-X)和--strategy(短-s)? 有很多关于 merge strategies 的问题.但是没有人解释这些选项之间的区别。
耦合策略和非耦合策略有什么区别? 谢谢回答。 最佳答案 当策略类知道上下文时,或者当客户端知道策略具体类时,策略是耦合的。 我们可以阅读 here (有一些小的修改): Usually each st
我是 hibernate 新手。我不明白以下两种主键生成策略: 身份 顺序 有人能解释一下这两者是如何工作的吗?这两者有什么区别? 最佳答案 引用 Java Persistence/Identity
我正在尝试调试我在编写内核时遇到的链接器问题。 问题是我有一个变量 SCAN_CODE_MAPPING我无法使用 - 它似乎是空的或其他东西。我可以通过改变我链接程序的方式来解决这个问题,但我不知道为
今天,当我找到一种方法来破坏我们程序中的某些功能时,我正在为客户做一些事情。 (代码实际上是遗留代码,它已经开发了大约 10 年,而我在这里只工作了大约一年。) 它不会导致错误或导致程序崩溃,但如果用
我想使用 Strategy Pattern为第三方类中的成员实现一些定制的格式化行为。我希望第三方只需注释类成员以指示他们是否应该使用格式策略(A、B 或 C),然后使用他们类的实例调用我的“格式”函
我试图将 CopyOnWriteArrayList 理解为我的代码: 我的代码是: public class AuditService { private CopyOnWriteArrayLi
在 git 中,我有一个 master 分支,我在其中开发我的应用程序。除了应用程序,我还需要开发它的演示版本。 我考虑过为 demo 创建一个永远不会 merge 到 master 中的单独分支。主
1、意图 定义一系列的算法,把它们一个个封装起来,并且使它们可相互替换。策略模式可以使算法可独立于使用它的客户而变化 策略模式变化的是算法 2、策略模式结构图 3、策略模式中主要
抽象策略(Strategy)角色:定义所有支持的算法的公共接口。通常是以一个接口或抽象来实现。Context使用这个接口来调用其ConcreteStrategy定义的算法。 具体策略(Concre
模板模式(Template Pattern)中,一个抽象类公开定义了执行它的方法的方式/模板。它的子类可以按需要重写方法实现,但调用将以抽象类中定义的方式进行 模板模式属于行为型模式 摘要 1、
我希望这是一个可以接受的问题。我理解递归的思维模式,我想考虑基本情况,然后是递归情况,但是对于一些更困难的 BST 问题,我只是画了空白,感觉就像我迷失了方向而没有一个好的方向。 例如,对于链表,似乎
是否有人考虑过为 Azure 存储队列实现策略,允许以任意顺序(除了先进先出)使消息出队。例如,有些人可能对 LIFO 感兴趣,有些人可能希望在不太重要的消息之前将“重要”消息出队,等等。 就我个人而
虽然多线程在某些情况下速度更快,但有时我们只想生成多个工作进程来完成工作。这样做的好处是,如果其中一个 worker 崩溃,主应用程序不会崩溃,而且用户不需要太担心互锁问题。 COM+ 的 Appli
我的应用程序将对我的对象有不同的策略。实现这一目标的最佳方法是什么?理想情况下,我想从某些关系数据库动态加载策略实现。但我不知道该怎么做。最好的方法是什么? 例如,假设我们要将策略 Strategy1
上下文 首先,感谢您的假设。它既非常强大又非常有用! 我编写了一个假设策略来生成以下形式的单调(ANDS 和 OR)策略表达式: (A and (B or C)) 这可以被认为是一个树结构,其中 A、
问题 我有一个大类(大约 1500 LOC),它使用不同的“策略”将数据从一个对象转换到另一个对象。我在这里有那个类的表示: public class FooService implements Fo
我正在阅读 Effective Java。在讨论使用函数对象作为策略的部分中,存在以下段落。 Because the strategy interface serves as a type for a
我是 C# 4.0 和 WPF 的新手,我正准备开始一个新的应用程序。 来自 C++/MFC 世界,我对测试与最新技术一起使用的策略很感兴趣。 例如: 单元测试 功能测试 界面测试 其他? 如有任何建
我是一名优秀的程序员,十分优秀!