ngx-prompt-kit
All blocks

Block

Code review thread

A code review pattern: paste in code, the assistant returns a critique with markdown commentary and a side-by-side before/after.

Snippet → review with diff

Review this — it's stuck in a recursion loop. session.ts (before)typescript
function refreshSession(token: string) {
  if (!token) throw new Error('no token');
  const decoded = verifyToken(token);
  if (decoded.expired) {
    return refreshSession(decoded.refreshToken);
  }
  return decoded;
}
AI

The cycle is the recursive call — refreshSession calls itself with the refresh token, which goes back through verifyToken. Fix: decode without verifying, then exchange the refresh token via a separate code path.

session/refresh.ts (after)suggested
// session/refresh.ts — extracted to break the cycle
function refreshSession(token: string) {
  const decoded = decodeToken(token);
  if (decoded.expired) {
    return exchangeRefreshToken(decoded.refreshToken);
  }
  return decoded;
}