Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
secondsky avatar

Session Management

  • 314 installs
  • 202 repo stars
  • Updated August 4, 2026
  • secondsky/claude-skills

session-management is an agent skill that implements secure session management with JWT tokens, Redis storage, refresh flows, and cookie configuration for developers who build authentication and logout systems.

About

session-management is an MIT-licensed agent skill from secondsky/claude-skills that guides agents through production-grade user session handling. The skill documents token-based sessions with JavaScript examples using jsonwebtoken: separate access and refresh tokens signed with distinct secrets, access tokens carrying userId and role claims, and refresh tokens scoped for rotation. It covers Redis-backed session storage, refresh-token exchange flows, HttpOnly Secure SameSite cookie settings, and secure logout that invalidates server-side state. Developers invoke session-management when scaffolding login endpoints, hardening cookie delivery, or replacing naive localStorage JWT patterns with server-validated sessions. The skill emphasizes short-lived access tokens—its sample uses a 1h expiresIn window—and longer refresh handling with explicit revocation on logout. Reach for it during auth feature work on Node.js APIs or any stack pairing JWT with Redis. Skip it when using hosted identity providers that fully manage sessions without custom token code.

  • session-management

Session Management by the numbers

  • 314 all-time installs (skills.sh)
  • +14 installs in the week ending Aug 5, 2026 (Skillselion tracking)
  • Ranked #1,288 of 4,347 Backend & APIs skills by installs in the Skillselion catalog
  • Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/secondsky/claude-skills --skill session-management

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs314
repo stars202
Last updatedAugust 4, 2026
Repositorysecondsky/claude-skills

How do you implement secure JWT session management?

Use session-management for development tasks

Who is it for?

Backend developers building custom login, refresh, and logout on Node.js APIs with JWT and Redis.

Skip if: Projects using Auth0, Clerk, or Firebase Auth that manage sessions entirely outside custom JWT code.

When should I use this skill?

A user asks to implement JWT sessions, refresh tokens, Redis session storage, secure cookies, or logout.

What you get

Auth handlers with signed JWT pairs, Redis session records, secure cookie settings, and logout invalidation logic.

  • JWT auth middleware
  • Refresh and logout handlers

By the numbers

  • Sample access tokens use expiresIn of 1h in the provided JWT example

Files

SKILL.mdMarkdownGitHub ↗

Session Management

Implement secure session management with proper token handling and storage.

Token-Based Sessions

const jwt = require('jsonwebtoken');

function generateTokens(user) {
  const accessToken = jwt.sign(
    { userId: user.id, role: user.role, type: 'access' },
    process.env.JWT_SECRET,
    { expiresIn: '1h' }
  );

  const refreshToken = jwt.sign(
    { userId: user.id, type: 'refresh' },
    process.env.REFRESH_SECRET,
    { expiresIn: '7d' }
  );

  return { accessToken, refreshToken };
}

Redis Session Storage

const redis = require('redis');
const client = redis.createClient();

class SessionStore {
  async create(userId, sessionData) {
    const sessionId = crypto.randomUUID();
    await client.hSet(`sessions:${userId}`, sessionId, JSON.stringify({
      ...sessionData,
      createdAt: Date.now()
    }));
    await client.expire(`sessions:${userId}`, 86400 * 7);
    return sessionId;
  }

  async invalidateAll(userId) {
    await client.del(`sessions:${userId}`);
  }
}

Cookie Configuration

app.use(session({
  name: 'session',
  secret: process.env.SESSION_SECRET,
  cookie: {
    httpOnly: true,
    secure: process.env.NODE_ENV === 'production',
    sameSite: 'strict',
    maxAge: 3600000, // 1 hour
    domain: '.example.com'
  },
  resave: false,
  saveUninitialized: false
}));

Token Refresh Flow

app.post('/auth/refresh', async (req, res) => {
  const { refreshToken } = req.cookies;

  try {
    const payload = jwt.verify(refreshToken, process.env.REFRESH_SECRET);
    if (payload.type !== 'refresh') throw new Error('Invalid token type');

    const user = await User.findById(payload.userId);
    const tokens = generateTokens(user);

    res.cookie('accessToken', tokens.accessToken, cookieOptions);
    res.json({ success: true });
  } catch (err) {
    res.status(401).json({ error: 'Invalid refresh token' });
  }
});

Security Requirements

  • Use HTTPS exclusively
  • Set httpOnly and sameSite on cookies
  • Implement proper token expiration
  • Use strong, unique secrets per environment
  • Validate signatures on every request

Never Do

  • Store sensitive data in tokens
  • Transmit tokens via URL parameters
  • Use weak or shared secrets
  • Skip signature validation

Related skills

How it compares

Use session-management for roll-your-own JWT plus Redis auth; use auth0-cli when Auth0 tenants and apps are managed via CLI instead.

FAQ

What does session-management implement?

The session-management skill implements JWT-based sessions with separate access and refresh tokens, Redis storage, secure cookie configuration, and logout invalidation. It targets custom authentication backends rather than hosted identity platforms.

Which libraries does session-management reference?

The session-management skill references jsonwebtoken for signing access and refresh tokens in JavaScript examples. It pairs tokens with Redis for server-side session state and documents cookie flags for browser clients.

Backend & APIsbackendintegrations

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.