Skip to content

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.

Notifications You must be signed in to change notification settings

febeeh/redis-session-storage-adapter-for-authjs-nextauth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Redis Session Storage Adapter for Auth.js/Next-Auth

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.

1. Install the required dependencies:

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.

2. Set up environment variables:

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.

3. Copy the customDBAdapter.ts and redis.ts Files

To use the adapter, copy the customDBAdapter.ts and redis.ts files into your ./lib directory.

4. Adding the Adapter to auth.ts

Import the customDBAdapter and redisClient:

import { customDBAdapter  } from "./lib/customDBAdapater";
import redisClient from "./lib/redis";

Add the Custom Adapter to NextAuth configuration:

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

Example

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.

About

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.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published