How to expire auth token passport.js on logout action?

Viewed 10

I want to create logout method, but I want the user JWT to be expired after logout action. I've checked the jwt package doesn't have anything like jwt.remove().

I am using this package https://www.npmjs.com/package/jsonwebtoken

const jwt = require("jsonwebtoken");

This is how I set the token in my login action

 const token = jwt.sign(payload, process.env.SECRET_KEY, {
      expiresIn: "1d",
    });

Logout:

const logout = (req, res) => {
  req.logout((err) => {
    if (err) {
      res.status(400).send("Something went wrong");
    }
    res.status(201).send("Success");
  });
};

With this req.logout() I am getting this error - Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client. So I guess I should somehow try and remove manually the JWT token?

0 Answers
Related