AI-Powered Code Review

The best way to review
pull requests.

AI-powered code review that catches bugs, enforces patterns, and ships feedback in seconds — not hours.

Free for open source  ·  No credit card required  ·  Setup in 2 minutes

GitReview — feat/auth-refactor #247
GitHub — octocat/app
🔒app.gitreview.dev/octocat/app/pull/247
←
refactor: migrate auth flow to JWT with refresh token rotation#247Open
feat/auth-refactor→main
+284/-97
src / lib /api.ts
@@ -1,8 +1,10 @@ import type { RequestInit } from 'node-fetch'
1
1
import { z } from 'zod'
2
-
import { getSession, destroySession } from './session'
2
+
import { signToken, verifyToken, refreshAccessToken } from './jwt'
3
+
import type { JWTPayload, TokenPair } from './jwt'
3
4
4
-
const TOKEN_EXPIRY = 3600 // 1 hour in seconds
5
+
const ACCESS_TOKEN_TTL = 900 // 15 minutes
6
+
const REFRESH_TOKEN_TTL = 604800 // 7 days
@@ -28,14 +32,24 @@ export async function createAuthTokens(userId: string)
28
32
export async function createAuthTokens(userId: string): Promise<TokenPair> {
29
-
const token = await signToken({ sub: userId, exp: TOKEN_EXPIRY })
33
+
const [accessToken, refreshToken] = await Promise.all([
34
+
signToken({sub: userId, type: 'access', exp: ACCESS_TOKEN_TTL}),
35
+
signToken({sub: userId, type: 'refresh', exp: REFRESH_TOKEN_TTL}),
36
+
])
30
37
return { accessToken, refreshToken }
@@ -56,6 +68,18 @@ export async function handleTokenRefresh(token: string)
56
68
export async function handleTokenRefresh(token: string) {
57
-
const payload = verifyToken(token)
69
+
const payload = await verifyToken(token)
70
+
if (!payload || payload.type !== 'refresh') {
71
+
throw new Error('Invalid or expired refresh token')
AI
GitReview AISecurityjust now
Throwing a generic Error here leaks implementation details to the client. Consider using a typed AuthError class with a stable error code (e.g. ERR_INVALID_REFRESH_TOKEN) that you can safely serialize in API responses without exposing internals.
72
+
}
73
+
return refreshAccessToken(payload.sub)
58
74
}
AI Review
SUMMARY

This PR migrates from session-based auth to JWT with refresh token rotation. The access/refresh token split is correctly implemented. Main concern is error handling — several throw new Error() calls should use typed errors.

ISSUES FOUND3 total
Generic error leaks internals
api.ts · L71
L71
Refresh token not invalidated on use
jwt.ts · L34–42
L34
Missing rate limiting on refresh endpoint
api.ts · L88
L88
Suggested fix · L71
- throw new Error('Invalid or expired refresh token') + throw new AuthError( + 'ERR_INVALID_REFRESH_TOKEN', + { statusCode: 401 } + )
AI-powered review summaries
Instant file search
Multi-account support
Inline diff comments
Keyboard-first navigation