I understand how to use JWT tokens for authentication/authorization. However, there is not a specific method call or event that invokes the code to provide a new token at the path "/token" using the refresh token. Please answer, does the code below get called automatically behind-the-scenes by NPM package 'jsonwebtoken' when the token expires, or is there a manual way to call this that I am missing in the tutorials?
let refreshTokens = []; //in production use redis or other...
app.post('/token', (req, res) => {
const refreshToken = req.body.token;
if (refreshToken == null) return res.sendStatus(401);
if (refreshTokens.includes(refreshToken)) return res.sendStatus(403);
jwt.verify(refreshToken, process.env.REFRESH_TOKEN_SECRET, (err, user) => {
if (err) return res.sendStatus(403);
const accessToken = generateAccessToken({ name: user.name });
res.json({ accessToken: accessToken });
})
})