meridian
review
⌘K
phoenix / refactor-auth-logic

Implementation of JWT stateless rotation

compiled 04:12s ago
import { rotateToken } from './auth.utils';
import { db } from '../database';
// Initialize token rotation window
export const handleRotation = async (userId: string, token: string) => {
const session = await db.sessions.findUnique({ where: { token } });
if (!session) throw new Error('INV_SESSION');
const { newToken, expiresAt } = await rotateToken(session);
return db.sessions.update({
where: { id: session.id },
data: { token: newToken, lastRotated: new Date() }
});
};
// TODO: Add edge case for simultaneous refresh
const LOCK_TIMEOUT = 5000;
const rotationLock = new Map<string, boolean>();
Risk Assessment
MEDIUM

Synchronous DB writes on every refresh may cause bottleneck during peak traffic spikes. Recommend moving rotation to a background job or introducing a grace period buffer.

CRITICAL

Lack of idempotent checks for concurrent refresh requests could invalidate a valid user session if two clients pulse at the same millisecond.