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.

npm install react-router-redis-session
INSTALL
IMPORT
SIG · REACT-ROUTER-REDIS
R
react-router-redis-session
storagejavascriptv0.0.3
harness data pending
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.

createRedisSessionStorage
import { createRedisSessionStorage } from 'react-router-redis-session'
const createRedisSessionStorage = require('react-router-redis-session')
Package exports a single named function. Default import is not available. CommonJS require works but TypeScript may complain if no allowSyntheticDefaultImports.
createRedisSessionStorage
import type { SessionData } from 'react-router'; const sessionStorage = createRedisSessionStorage<SessionData>({...})
const sessionStorage = createRedisSessionStorage<SessionData>({...}) without type import
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.
Redis (Type)
import type { Redis } from 'ioredis' or 'redis'
import { Redis } from 'react-router-redis-session'
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').

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 issues
gotcharedisConfig and redisClient are mutually exclusive but no runtime check prevents passing both; one will be ignored.
fix
Pass only one of redisConfig or redisClient.
affects: *
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.
fix
Use `redis` v3.x. If you need ioredis, provide a pre-created client via redisClient.
affects: *
gotchaSession data generics default to empty object; type safety is lost if not provided. No type validation at runtime.
fix
Always pass a generic type argument: createRedisSessionStorage<MySessionData>(...)
affects: *
gotchaCookie secrets must be at least one string; passing empty array will throw at runtime (from react-router).
fix
Ensure secrets array has at least one string.
affects: *
Errors
Common errors & fixes
TypeError: createRedisSessionStorage is not a function
Default import used instead of named import.
fix
Change to `import { createRedisSessionStorage } from 'react-router-redis-session';`
Unhandled Rejection: RedisClient is not a constructor
Attempting to pass redisConfig but have incompatible redis version (e.g., ioredis instead of redis).
fix
Install `redis` v3.x or provide a pre-created client via redisClient.
Property 'getSession' does not exist on type '...'
TypeScript cannot infer session type; likely missing generic or wrong import.
fix
Add generic: `const sessionStorage = createRedisSessionStorage<YourDataType>(...)`
Secret can not be empty
Cookie secrets array is empty.
fix
Provide at least one secret string in the cookie configuration.
Upgrade
Version history
0.0.3latest on npm
Audit
Dependencies
react-routerrequiredPeer dependency for the SessionIdStorageStrategy type and session interface; must be installed separately.
redisoptionalRequired for Redis client if you connect via redisConfig; if you provide your own redisClient, this is still needed if you use the config approach.
Agent activity
23 hits · last 30 days
node
20
Amazon
1
OpenAI (training)
1
Resources
react-router-redis-session — npm install react-router-redis-session · libregistry