index.js
function _decode (cookieName, cookieDomain, publicUrl) {
  return (req, res, next) => {
    // JWT in a cookie = already active session
    const cookies = new Cookies(req, res)
    const token = _getCookieToken(cookies, req, cookieName, cookieDomain, publicUrl)
    if (token) {
      req.user = jwt.decode(token)
      _setOrganization(cookies, cookieName, req, req.user)
    }
    next()
  }
}
function _decode (cookieName, cookieDomain, publicUrl) {
  return (req, res, next) => {
    // JWT in a cookie = already active session
    const cookies = new Cookies(req, res)
    const token = _getCookieToken(cookies, req, cookieName, cookieDomain, publicUrl)
    if (token) {
      req.user = jwt.decode(token)
      _setOrganization(cookies, cookieName, req, req.user)
    }
    next()
  }
}
function _decode ( cookieName , cookieDomain , publicUrl ) { return ( req , res , next ) => { // JWT in a cookie = already active session const cookies = new Cookies ( req , res ) const token = _getCookieToken ( cookies , req , cookieName , cookieDomain , publicUrl ) if ( token ) { req . user = jwt . decode ( token ) _setOrganization ( cookies , cookieName , req , req . user ) } next ( ) } }
This middleware checks if a user has an active session and defines req.user Contrary to auth it does not validate the token, only decode it.. so it faster but it is limited to routes where req.user is informative
This middleware checks if a user has an active session and defines req . user Contrary to auth it does not validate the token only decode it .. so it faster but it is limited to routes where req . user is informative