title: Using both JWT and Passportjs
body: <p>I am working on mern stack application where I use both jwt for registration and passportjs for social login. I am currently facing issue of authenticating routes.</p>
  <p>Here is the Auth middleware of jwt and passportjs:</p>
  <pre><code>     const jwt = require(&quot;jsonwebtoken&quot;)
      const Auth = async (req,res,next)=&gt;{
          //if(req,headers)
          try {
              const token = req.headers.authorization.split(&quot; &quot;)[1]
              if(!token){
                  return res.status(404).json({msg:&quot;no token authorization&quot;})
              }
              let decodeData
              
              decodeData = jwt.verify(token, process.env.JWT_SECRET)
              req.userId = decodeData.user.id
              next()
          } catch (error) {
              console.error(error.message);
              res.status(500).send(&quot;Server Error&quot;);
          }
      } 
      
      const passportAuth = (req,res,next)=&gt;{
          if(!req.user){
              return res.status(404).json({msg:&quot;user not loggged in&quot;})
          }else{
              next()
          }
      }
  
  module.exports = Auth
  module.exports = passportAuth
  </code></pre>
  <p>logged in user can create post but here I have jwt auth and passportauth.</p>
  <p>if use both [Auth, passportAuth] in the route it wont be working becuase either user have to logged in with google or simple signup registration. Here is the authenticated route code</p>
  <pre><code>route.post(&quot;/&quot;,[auth,passportAuth], async(req,res)=&gt;{
      const post = req.body
      try {
          const createpost = new Post({
              tags:post.tags,
              creator:post.creator,
              title: post.title,
              message: post.message,
              selectedFile: post.selectedFile,
              user:req.userId
          })
          await createpost.save()    
          res.json(createpost)
      } catch (error) {
          console.error(error.message);
          res.status(500).send(&quot;Server Error&quot;);
      }
  })
  </code></pre>
  <p>So what should I do here?</p>