2016-09-28 48 views
0

我創建一個策略對象是這樣的:護照LocalStrategy不一致的類名

var strat = new LocalStrategy({ 
      usernameField: 'email' 
     }, 
     function(username, password, done) { 
      User.findOne({ email: username }, function (err, user) { 
       if (err) { return done(err); } 
       // Return if user not found in database 
       if (!user) { 
        return done(null, false, { 
         message: 'User not found' 
        }); 
       } 
       // Return if password is wrong 
       if (!user.validPassword(password)) { 
        return done(null, false, { 
         message: 'Password is wrong' 
        }); 
       } 
       // If credentials are correct, return the user object 
       return done(null, user); 
      }); 
     } 
    ); 

在我的調試器,我看到STRAT對象是類「戰略」的一個實例。

enter image description here

它不應該是 「LocalStrategy」 的一個實例,因爲它是通過LocalStrategy conscructor產生的?

回答

1

下面是什麼,通常做的設置代碼示例一塊passportjs使用本地策略

var LocalStrategy = require('passport-local').Strategy; 

正如你所看到的策略是導出的符號和the name of the strategy constructor的名稱。 LocalStrategy只是您正在使用的局部變量的名稱。