JWT refresh token string to verify and decode
Decoded token payload containing user information and JWT claims
// Verify refresh token during token renewal
try {
const decoded = verifyRefreshToken(refreshToken);
console.log(decoded.sub); // User ID
console.log(decoded.email); // User email
console.log(decoded.role); // User role
} catch (error) {
if (error.name === 'TokenExpiredError') {
console.log('Refresh token has expired');
} else if (error.name === 'JsonWebTokenError') {
console.log('Invalid refresh token');
}
}
Verify and decode JWT refresh token
Validates a refresh token's signature and expiration using the JWT_REFRESH_SECRET, then returns the decoded payload containing user information. This function is used during token renewal operations to ensure the refresh token is valid and extract user data for generating new tokens.
The function performs cryptographic verification of the token signature and automatically checks expiration time. If verification fails, it throws a JsonWebTokenError that should be handled by the calling code.