Registry /
storage / react-router-redis-session
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;
}
Errors
Common errors & fixes
TypeError: createRedisSessionStorage is not a function
Default import used instead of named import.
fixChange 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).
fixInstall `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.
fixAdd generic: `const sessionStorage = createRedisSessionStorage<YourDataType>(...)`
Secret can not be empty
Cookie secrets array is empty.
fixProvide at least one secret string in the cookie configuration.
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.