title: extract the expiration datetime from jsonwebtoken
body: <p>To invalidate a token it's as far as I know the best way to store the token and it's expiration datetime to the database. To validate it, you simply have to select it from the database and if it exists, you know it was invalidated. Further you can remove every expired token by it's expiration datetime from the database.</p>
  
  <p>So I created a middleware that extracts the token from the authorization headers and it should attach the token and the expiration datetime to the <code>request</code> object. The datetime is required for the <code>signOut</code> route to invalidate the token.</p>
  
  <pre><code>  async use(req: any, res: Response, next: NextFunction) {
      try {
        const headers: IncomingHttpHeaders = req.headers;
        const authorization: string = headers.authorization;
        const bearerToken: string[] = authorization.split(' ');
        const token: string = bearerToken[1];
  
        if (await this.authenticationsRepository.findByEncodedToken(token)) { // invalidated token?
          throw new Error(); // jump to catch
        }
  
        req.tokenPayload = verifyToken(token); // calls jwt.verify with secret
        next();
      } catch (error) {
        throw new UnauthorizedException();
      }
    }
  </code></pre>
  
  <p>But how can I extract the <code>exp</code> attribute from the token to calculate the expiration date time?</p>