How can i create a superuser authentication with passport js and express here is what my looks like
const jwtStrategy = require('passport-jwt').Strategy;
const ExtractJwt = require('passport-jwt').ExtractJwt;
const User = require('../models/user');
const config = require('./config');
module.exports = function(passport){
let ops = {}
ops.jwtFromRequest = ExtractJwt.fromAuthHeader();
ops.secretOrKey = config.secret
passport.use(new jwtStrategy(ops, (jwt_payload,done)=>{
console.log(jwt_payload);
User.getUserById(jwt_payload._doc._id,(err,user)=>{
if (err) {
console.log(err);
return done(null,false)
}
if (user) {
return done(null,user)
}else {
return done(null,false)
}
})
}))
}
But when i can authenticate the user has access to all routes i want to have another auth where users will have access to a particular route superuser
oradmin
via Sagaya Adols
No comments:
Post a Comment