aj-geddes avatar

Session Management

This handles the full authentication state lifecycle: JWT generation and validation, token refresh flows, Redis-backed session storage, CSRF protection, and proper logout cleanup. You get working examples in both Python/Flask and Node.js/Express, plus middleware chains that validate tokens on every request. The skill covers the security fundamentals you actually need: httpOnly cookies, proper token expiration, strong secrets, and session timeout handling. It's opinionated about not using localStorage for tokens and always running over HTTPS, which is the right call. Good for building login systems from scratch or fixing security gaps in existing auth flows.

skills.sh installs
466
GitHub stars
379
last updated
Aug 21, 2026

Install

$ npx -y skills add aj-geddes/useful-ai-prompts --skill session-management --agent claude-code

Installs into .claude/skills of the current project.

Files

Session Management

Table of Contents

Overview

Implement comprehensive session management systems with secure token handling, session persistence, token refresh mechanisms, proper logout procedures, and CSRF protection across different backend frameworks.

When to Use

  • Implementing user authentication systems
  • Managing session state and user context
  • Handling JWT token refresh cycles
  • Implementing logout functionality
  • Protecting against CSRF attacks
  • Managing session expiration and cleanup

Quick Start

Minimal working example:

# Python/Flask Example
from flask import current_app
from datetime import datetime, timedelta
import jwt
import os

class TokenManager:
    def __init__(self, secret_key=None):
        self.secret_key = secret_key or os.getenv('JWT_SECRET')
        self.algorithm = 'HS256'
        self.access_token_expires_hours = 1
        self.refresh_token_expires_days = 7

Sponsors

Details

Repository
github.com/aj-geddes/useful-ai-prompts
Categories
Backend & APIs, Security, AI & Agent Building
First seen
Jun 3, 2026

More from aj-geddes/useful-ai-prompts

All 258
1aj-geddes avatarspring-boot-applicationaj-geddes/useful-ai-promptsBuild enterprise Spring Boot applications with annotations, dependency injection, data persistence, REST controllers, and security. Use when developing Spring a463skills.sh installs
2aj-geddes avatarserverless-architectureaj-geddes/useful-ai-promptsDesign and implement serverless applications using AWS Lambda, Azure Functions, and GCP Cloud Functions with event-driven patterns and orchestration.461skills.sh installs
3aj-geddes avatartransaction-managementaj-geddes/useful-ai-promptsManage database transactions for data consistency. Use when implementing ACID compliance, handling concurrency, or managing transaction isolation levels.461skills.sh installs
4aj-geddes avatarsecrets-rotationaj-geddes/useful-ai-promptsImplement automated secrets rotation for API keys, credentials, certificates, and encryption keys. Use when managing secrets lifecycle, compliance requirements,459skills.sh installs
5resend avatarsend-emailresend/resend-skillsUse when sending transactional emails (welcome messages, order confirmations, password resets, receipts), notifications, or bulk emails via Resend API.459skills.sh installs
6tamtom avatargplay-cli-usagetamtom/gplay-cli-skillsGuidance for using the Google Play Console CLI in this repo (flags, output formats, pagination, auth, and discovery). Use when asked to run or design gplay comm458skills.sh installs