简体   繁体   English

护照.js +快递:TypeError('Router.use()需要中间件功能,但得到了'+ gettype(fn))

[英]passport.js + express: TypeError('Router.use() requires a middleware function but got a ' + gettype(fn))

I use pasport.js + Express.js and got error 我使用pasport.js + Express.js并收到错误

TypeError('Router.use() requires a middleware function but got a ' + gettype(fn))

with this code 用这个代码

passport/local.js 护照/ local.js

var LocalStrategy = require("passport-local").Strategy;
var models = require("../../models");

module.exports = new LocalStrategy(
    function(username,password,done){
        models.User.findOne(
            {
                where:{username:username}
            },function(err,user){
                if(err){return done(err);}
                if(!user){return done(null,false,{message:"no such user"});}
                if(!user.validPassword(password)){return done(null,false,{message:"invalid password"});}
                return done(null,user);
            }
        );
    }
);

passport.js passport.js

var passport = require("passport");
var models = require("../models");
var local = require("./passport/local");

module.exports = () => {
    passport.serializeUser((user,done) => {
        done(null,user.id);
    });

    passport.deserializeUser((id,done) => {
        models.User.findOne({
            where:{id:id}
        }).then(user => {
            done(null,user);
        }).catch(err => {
            done(err,null);
        });
    });

    console.log(typeof(local));
    passport.use(local);
}

console.log(typeof(local)); 的console.log(typeof运算(本地)); return "object". 返回“对象”。 but passport.use() need function? 但是passport.use()需要功能吗?

How can i solve this? 我该如何解决?

Usually this error comes from a missing export in one of the files that declares your routes. 通常,此错误是由于在声明您的路线的文件之一中缺少导出而引起的。 Please double check these files. 请仔细检查这些文件。

Also I checked and the code above works as it is. 我也检查了上面的代码,按原样工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Api : Express : throw new TypeError('Router.use() 需要一个中间件函数,但得到了一个 ' + gettype(fn)) - Api : Express : throw new TypeError('Router.use() requires a middleware function but got a ' + gettype(fn)) 表达错误:抛出新的TypeError('Router.use()需要中间件功能,但得到了'+ gettype(fn)); - Express error: throw new TypeError('Router.use() requires middleware function but got a ' + gettype(fn)); Node.js / express-Router.use()需要中间件功能,但是得到了'+ gettype(fn)); - Nodejs/express - Router.use() requires middleware function but got a ' + gettype(fn)); TypeError('Router.use()需要中间件功能,但得到了'+ gettype(fn))FeathersJS - TypeError('Router.use() requires a middleware function but got a ' + gettype(fn)) FeathersJS Express.js:抛出新的TypeError('Router.use()需要中间件功能,但得到了'+ gettype(fn)) - Expressjs: throw new TypeError('Router.use() requires a middleware function but got a ' + gettype(fn)) throw new TypeError('Router.use() 需要中间件函数,但得到了一个 ' + gettype(fn)); - throw new TypeError('Router.use() requires middleware function but got a ' + gettype(fn)); throw new TypeError('Router.use() 需要一个中间件 function 但得到了一个 + gettype(fn))。 (其他问题) - throw new TypeError('Router.use() requires a middleware function but got a + gettype(fn)). (other problem) 我运行此代码,但显示 router.use() 需要中间件功能,但出现 ' + gettype(fn) 这个错误 - i run this code but showing router.use() requires a middleware function but got a ' + gettype(fn) this error Express 路由器:Router.use() 需要中间件 function 但得到了 Object - Express router : Router.use() requires a middleware function but got a Object EXPRESS:Router.use() 需要一个中间件函数,但得到了一个对象 - EXPRESS: Router.use() requires a middleware function but got a Object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM