Performance: Authentication with JWT token
MEDIUM IMPACT
This affects page load speed by adding token validation steps during API calls and impacts interaction responsiveness when verifying tokens.
public boolean validateToken(String token) {
// Decode token with lightweight parsing
Claims claims = Jwts.parser().setSigningKey(secret).parseClaimsJws(token).getBody();
// Use cached user roles or embed roles in token to avoid DB call
return claims.getExpiration().after(new Date());
}public boolean validateToken(String token) {
// Decode token without caching
Claims claims = Jwts.parser().setSigningKey(secret).parseClaimsJws(token).getBody();
// Perform expensive DB call to verify user roles every request
User user = userRepository.findByUsername(claims.getSubject());
return user != null && user.hasValidRoles();
}| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Validating JWT with DB call every request | 0 (server-side) | 0 | 0 | [X] Bad |
| Validating JWT with embedded claims and no DB call | 0 (server-side) | 0 | 0 | [OK] Good |