import NextAuth from 'next-auth'
import { ChatBotKitContactAdapter, ContactMemoryStore } from '@chatbotkit/nextauth/contact'
export default NextAuth({
adapter: ChatBotKitContactAdapter({
secret: process.env.CHATBOTKIT_API_SECRET,
store: new ContactMemoryStore(), // Use Redis or another store in production
autoCreateContact: true,
autoUpdateContact: true,
autoDeleteContact: false,
}),
// ... other NextAuth configuration
})
A NextAuth.js adapter that integrates with the ChatBotKit Contact API for user management within a single account.
This adapter enables you to authenticate users as contacts within a single ChatBotKit account using NextAuth.js. Unlike the Partner adapter which creates separate sub-accounts for each user, this adapter manages users as contacts within your main account, making it ideal for scenarios where you want all users to interact within the same ChatBotKit environment.
Overview
The ChatBotKitContactAdapter bridges NextAuth.js authentication with ChatBotKit's Contact API. When users authenticate through your application, this adapter automatically manages them as contacts within your account, creating, updating, or removing contacts based on your configuration.
Key Differences from Partner Adapter
Use Cases
This adapter is ideal for:
Storage Requirements
This adapter requires a store implementation for persisting verification tokens and session data. The store interface is compatible with Vercel KV and Redis, but you can implement your own storage backend by extending the ContactStore class.
Important: Do not use ContactMemoryStore in production environments as it doesn't persist data across server restarts or multiple instances.
User Lifecycle Control
autoCreateContact: When true, new contacts are created automatically on first sign-in. Recommended for self-service applications.autoUpdateContact: When true, contact information is synchronized on each sign-in. Recommended to keep user data in sync.autoDeleteContact: When true, contacts are deleted when users are removed from NextAuth. Use with caution in production.Production Recommendations
For production environments:
autoCreateContact: falseand manually approve contact creationautoUpdateContact: trueto keep contact data synchronizedautoDeleteContact: falseto prevent accidental data loss