koa 项目实战(九)passport验证token
1.安装模块 npm install koa-passport -D npm install passport-jwt -D 2.解析token 根目录/config/passport.js const JwtStrategy = require('passport-jwt').Strategy, ExtractJwt = require('passport-jwt').ExtractJwt; const keys = require('../config/keys'); const opts = {}; opts.jwtFromRequest = ExtractJwt.fromAuthHeaderAsBearerToken(); opts.secretOrKey = keys.secretOrkey; const mongoose = require('mongoose'); const User = mongoose.model('users'); module.exports = passport => { passport.use(new JwtStrategy(opts, async function (jwt_payload, done) { // console.log(jwt_payload); const user = await User.findById