Verify your own completed code changes using the repo's existing infrastructure and an independent evaluator context. Use after implementing a change when you need to run unit or integration tests, check build or lint gates, prove the real surface works with evidence, and challenge the changed code for clarity, deduplication, and maintainability. If the repo is not verifiable yet, hand off to `agent-readiness`; if you are reviewing someone else's code, use `review`.
97
100%
Does it follow best practices?
Impact
89%
1.02xAverage score across 3 eval scenarios
Passed
No known issues
The platform team at a SaaS company recently extended their TypeScript authentication service to support JWT refresh tokens. A developer added the new functionality under time pressure to meet a sprint deadline. The tech lead wants an independent review of the module before it merges to main — specifically focused on code quality, safety, and long-term maintainability rather than feature correctness.
The module handles token decoding, validation, and refresh. It has been working in local testing, but no one has reviewed the code shape since the new functionality was added. The tech lead is concerned about patterns that could cause silent failures in production, unclear error behavior, and code that a new team member might struggle to maintain.
Produce a file named review-report.md containing your code-shape findings. The report should:
The following file is provided as input. Extract it before beginning.
=============== FILE: inputs/token-manager.ts =============== // token-manager.ts // Utilities for JWT token handling in the auth service
function decodeToken(token: any): any { const parts = token.split('.'); return JSON.parse(Buffer.from(parts[1], 'base64').toString()); }
// Backup decode path used during migration function parseJwt(rawToken: any): any { const segments = rawToken.split('.'); return JSON.parse(Buffer.from(segments[1], 'base64').toString()); }
// Was used by the old session system - kept for now just in case function legacyValidate(token: string): boolean { return token.length > 0; }
export function validateToken(token: string): boolean { // Check if the token exists if (!token) { // Token is falsy, return false return false; }
try { // Decode the token to get the payload const payload = decodeToken(token); // Get the expiry from the payload const expiry = payload.exp; // Return true if the token has not yet expired return Date.now() / 1000 < expiry; } catch (e) { // Something went wrong return false; } }
export function getUserId(token: string): string { // Decode the token const payload = decodeToken(token); // Return the user ID field return payload.userId!; }
export function refreshToken(token: string): string { const payload = decodeToken(token) as { userId: string; role: string; iat: number }; // Build a new token payload return Buffer.from(JSON.stringify({ userId: payload.userId, role: payload.role, iat: Date.now(), exp: Date.now() / 1000 + 3600 })).toString('base64'); }
export function hasPermission(token: string, permission: string): boolean { try { const payload = decodeToken(token); const perms = payload.permissions as string[]; return perms.includes(permission); } catch (e) { return false; } }