This is a custom database adapter developed to use Redis as session storage, while allowing other databases to be used for storing user data. The adapter efficiently handles session management with Redis, providing seamless integration with Auth.js/Next-Auth.
To get started with the Redis Session Storage Adapter, you will need to install the following dependencies:
npm install ioredis
This will install ioredis for Redis integration.
In your .env file, add the following configuration for Redis:
REDIS_HOST=your_redis_host
REDIS_PORT=your_redis_port
REDIS_PASSWORD=your_redis_password
Replace your_redis_host
, your_redis_port
, and your_redis_password
with your Redis server details.
To use the adapter, copy the customDBAdapter.ts
and redis.ts
files into your ./lib
directory.
import { customDBAdapter } from "./lib/customDBAdapater";
import redisClient from "./lib/redis";
export default NextAuth({
adapter: customDBAdapter(
your-userdata-db-adapter-here,
redisClient
),
// Other NextAuth configuration
});
Add your user data DB adapter in place of your-userdata-db-adapter-here
. For more details about db adapter, checkout https://authjs.dev/getting-started/database
Check out the example
folder for a better understanding of how to integrate the Redis Session Storage Adapter with Auth.js/Next-Auth.
Done! You’re all set up to use the Redis Session Storage Adapter.