title: How to set Relogin on JWT expire MERN?
body: <p>I am facing an issue, my app is getting crashed with  JWT Token Expired Error. I have changed the secret key also but still same issue I am facing.</p>
  <p>Here is the code :</p>
  <p>Mddleware:</p>
  <pre><code>const auth = async (req, res, next) =&gt; {
    try {
      const token = req.headers.authorization.split(&quot; &quot;)[1];
      const isCustomAuth = token?.length &lt; 500;
      if (!token) 
      {return res.status(401).json({ message: &quot;No token provided&quot; });}
      let decodedData; 
      if(token &amp;&amp; isCustomAuth){
      decodedData= verifyToken(token);
      req.userId = decodedData?.id;
      }
      else{
        decodedData = jwt.decode(token);
        console.log(decodedData + &quot;decoded token&quot;);
        req.userId = decodedData?.sub;
      }
      next();
    } catch (error) {
      console.log(error);
      res.status(403).json({ message: &quot;Token is not valid&quot; });
      throw Error();
    }
  };
  </code></pre>
  <p>Token verification</p>
  <pre><code>import jwt from &quot;jsonwebtoken&quot;;
  
  const secret = process.env.SECRET;
  
  export const generateToken = (data) =&gt; {
      try {
          return jwt.sign({ email: data.email, id: data._id }, secret , { expiresIn: &quot;24h&quot; });
      } catch(e) {
          throw new Error(e)
      }
  }
  
  export const verifyToken = (token) =&gt; {
      try {
          return jwt.verify(token, secret);
      } catch(e) {
          throw new Error(e)
      }
  }
  </code></pre>
  <p>The app is getting crashed saying jwt expired error. Please help.</p>