const passport = require('passport')
const passportJwt = require('passport-jwt')
const userModel = require('../models/users')
const { ExtractJwt, Strategy } = passportJwt

let jwtOptions = {}
jwtOptions.jwtFromRequest = ExtractJwt.fromAuthHeader()
jwtOptions.secretOrKey = process.env.JWT_SECRET

const strategy = new Strategy(jwtOptions, (jwtPayload, next) => {
  userModel.findOne(jwtPayload.username)
    .then(user => {
      next(null, user)
    })
    .catch(err => next(err, false))
})

passport.use(strategy)

module.exports = passport

const passport = require('passport')
const passportJwt = require('passport-jwt')
const userModel = require('../models/users')
const { ExtractJwt, Strategy } = passportJwt

let jwtOptions = {}
jwtOptions.jwtFromRequest = ExtractJwt.fromUrlQueryParameter('token')
jwtOptions.secretOrKey = process.env.JWT_SECRET

const strategy = new Strategy(jwtOptions, (jwtPayload, next) => {
  userModel.findOne(jwtPayload.username)
    .then(user => {
      next(null, user)
    })
    .catch(err => next(err, false))
})

passport.use(strategy)

module.exports = passport

Make passwport-jwt exract tokens from the query params instea of the AuthHeaders
Make passwport-jwt exract tokens from the query params instea of the AuthHeaders

  --Auth headers are not being asent at the moment
    due to issues tyo do with CORS. Will find a
    fix sometime in the futur
