Registry / storage / react-router-redis-session

react-router-redis-session

JSON →
library0.0.3jsnpmunverified

Redis session backend for React Router v7 (formerly Remix). This library implements the session storage interface using Redis, supporting either Redis connection config or a pre-existing Redis client. Current version 0.0.3 is an early release with basic functionality. It provides a drop-in replacement for the built-in session storage, allowing server-side session management with Redis. No breaking changes reported yet. Alternative to other session adapters like @remix-run/server-runtime sessions.

storagesecurity
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Package exports a single named function. Default import is not available. CommonJS require works but TypeScript may complain if no allowSyntheticDefaultImports.

import { createRedisSessionStorage } from 'react-router-redis-session'

Type generics for session data must be provided when calling the function. The type must match the react-router SessionData shape; this import is from 'react-router', not this package.

import type { SessionData } from 'react-router'; const sessionStorage = createRedisSessionStorage<SessionData>({...})

The redisConfig.redisClient expects a Redis client instance, but the type is not re-exported. You must import the Redis type from your chosen Redis library (e.g., 'ioredis' or 'redis').

import type { Redis } from 'ioredis' or 'redis'

Sets up Redis-backed session storage with configuration, then retrieves a session from an incoming request's cookie.

import { createRedisSessionStorage } from 'react-router-redis-session'; import { createCookieSessionStorage } from 'react-router'; const sessionStorage = createRedisSessionStorage({ cookie: { name: 'my-session', secrets: ['my-secret'], sameSite: 'lax', path: '/', httpOnly: true, secure: process.env.NODE_ENV === 'production', }, options: { redisConfig: { host: process.env.REDIS_HOST ?? 'localhost', port: Number(process.env.REDIS_PORT ?? 6379), password: process.env.REDIS_PASSWORD ?? undefined, }, }, }); export async function getSession(request: Request) { const cookie = request.headers.get('Cookie'); const session = await sessionStorage.getSession(cookie); return session; }
Debug
Known footguns
gotcharedisConfig and redisClient are mutually exclusive but no runtime check prevents passing both; one will be ignored.
gotchaThe library uses the `redis` npm package (v3+) which requires Redis v6+ and may have breaking changes vs ioredis. The config type mirrors Redis.RedisOptions, which is outdated in newer versions of the redis package.
gotchaSession data generics default to empty object; type safety is lost if not provided. No type validation at runtime.
gotchaCookie secrets must be at least one string; passing empty array will throw at runtime (from react-router).
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
22 hits · last 30 days
gptbot
3
amazonbot
3
bytedance
2
ahrefsbot
1
Resources