鍍金池/ 問答/網(wǎng)絡(luò)安全  HTML/ koa-passport中間件中怎么具體使用?

koa-passport中間件中怎么具體使用?

const LocalStrategy = require('passport-local').Strategy
passport.use(new LocalStrategy(async function (username, password, done) {
  // FK: 根據(jù)username從數(shù)據(jù)庫或者其他存儲(chǔ)中拿到用戶信息
  let user = await userStore.getUserByName(username)
  // FK: 把傳入的password和數(shù)據(jù)庫中存儲(chǔ)的密碼進(jìn)行比較。當(dāng)然這里不應(yīng)該是明文,一般是加鹽的hash值
  if (user && validate(password, user.hash)) {
    done(null, user)
  } else {
    log.info(`auth failed for`, username)
    done(null, false)
  }
}))

koa-passport中間件使用的時(shí)候,里面有好多done回調(diào)函數(shù)么請(qǐng)問這個(gè)函數(shù)是在哪里實(shí)現(xiàn)的呢?是已經(jīng)實(shí)現(xiàn)好的?還是需要自己實(shí)現(xiàn)呢?看了好幾個(gè)教程,還是不明白如何使用,比較凌亂。
參考教程如下:
https://segmentfault.com/a/11...

https://segmentfault.com/a/11...

回答
編輯回答
執(zhí)念

done是回調(diào)函數(shù),意思是告訴調(diào)用你的人(passport)你已經(jīng)執(zhí)行完你要執(zhí)行的內(nèi)容了,讓它繼續(xù)跑它的邏輯。
一般是以done(err,data)的形式回調(diào)。

2017年5月9日 19:32