secondsky avatar

Session Management

Covers the essentials for JWT-based session management with Redis storage, token refresh flows, and secure cookie configuration. You get working code for generating access and refresh tokens with different lifespans, a Redis-backed session store that handles multiple sessions per user, and proper cookie settings including httpOnly and sameSite flags. The refresh endpoint implementation is straightforward and the security guidelines are practical reminders about HTTPS-only, avoiding URL-based token transmission, and validating signatures. Use this when you're setting up authentication from scratch or need to replace an insecure session system. The Redis integration is particularly useful if you need to invalidate all sessions for a user during logout or password changes.

skills.sh installs
427
GitHub stars
248
last updated
Aug 21, 2026

Install

$ npx -y skills add secondsky/claude-skills --skill session-management --agent claude-code

Installs into .claude/skills of the current project.

Files

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

Sponsors

Details

Repository
github.com/secondsky/claude-skills
Categories
Backend & APIs, Security, Databases
First seen
Jun 3, 2026

More from secondsky/claude-skills

All 146
1secondsky avataroauth-implementationsecondsky/claude-skillsOAuth 2.0 and OpenID Connect authentication with secure flows. Use for third-party integrations, SSO systems, token-based API access, or encountering authorizat422skills.sh installs
2davila7 avatarchromadavila7/claude-code-templatesOpen-source embedding database for AI applications. Store embeddings and metadata, perform vector and full-text search, filter by metadata. Simple 4-function AP421skills.sh installs
3davila7 avatartelegram-mini-appdavila7/claude-code-templatesExpert in building Telegram Mini Apps (TWA) - web apps that run inside Telegram with native-like experience. Covers the TON ecosystem, Telegram Web App API, pay420skills.sh installs
4xcrawl-api avatarxcrawlxcrawl-api/xcrawl-skillsUse this skill as the default XCrawl entry point for direct XCrawl requests, including single-URL fetch, format selection, sync or async execution, and JSON ext420skills.sh installs
5secondsky avataridempotency-handlingsecondsky/claude-skillsIdempotent API operations with idempotency keys, Redis caching, DB constraints. Use for payment systems, webhook retries, safe retries, or encountering duplicat415skills.sh installs
6davila7 avatarshopify-developmentdavila7/claude-code-templatesBuild Shopify apps, extensions, themes using GraphQL Admin API, Shopify CLI, Polaris UI, and Liquid. TRIGGER: "shopify", "shopify app", "checkout extension", "a411skills.sh installs