I am creating a jwt token and refresh token as follows
token = jwt.sign(
{ username: req.body.username },
"Secret-token”,
{ expiresIn: 60 }
);
refreshToken = jwt.sign(
{ username: req.body.username },
"some-secret-refresh-token",
{ expiresIn: "3h" }
);
And I can even verify the token received from the user with the following code
jwt.verify(token, "Secret-token", function(err, decoded) {
….
})
I store only the secret passphrase in auth/config.js. This is all I store. So, what is the need of storing token and refresh token in database, cookie, array etc. Since, I am able to decode the token with verify so why do we need to store. I am not matching or comparing the token with any stored token.
I can even check whether the token has expired or not using the following code
instanceof TokenExpiredError
Any clarification in this area would be highly appreciated. Thanks in advance!