title: Node.js express, request jwt token - how to properly get a new valid token if expired in request
body: <p>On successful login I store the returned JWT token in Session. 
  Then in my search route I'm accesing the api with the jwt token from the session and set in the header like this:   </p>
  
  <pre><code>router.post('/search', (req, res) =&gt; {
  
      var getToken = req.session.APIToken;
      var auth = 'Bearer '+getToken;
  
      request.get({
          headers: {
              "authorization": auth
          },
          url: "localhost/abc/search?name=peter"
      }, (error, response, body) =&gt; {
          if(error) {
              return console.dir(error);
          }
          var jsonBody = JSON.parse(body);
  
          if(jsonBody.status === 200) {
            console.log('Request successful!');
          }
          if(jsonBody.success === false) {
  
            /// ??? BUT what if the JWT token is expired! How do I properly refresh or get a new valid jwt token here? ///    
  
            console.log('Token expired!');
          }
      });
  
  });
  </code></pre>
  
  <p>BUT what if the JWT token is expired! How do I properly refresh or get a new valid jwt token here?</p>
  
  <p>I suppose with a callback function using the email and password saved in session? But how do I do this exactly or what is the best way to do this?</p>
  
  <p>Edit: I have two apps ... one frontend app ... and one separated API app. So when logging in ... I login in via the frontend app but get the JWT token from the API app. The login session from the frontend app is 360s ... the JWT token is valid for the 60s .... so in case the JWT token expired when the user does a search request ... I want to automatically generate a new token that finishes the request.</p>