Optionaloptions: EmailUserConfigimport NextAuth from 'next-auth'
import { ChatBotKitEmailProvider } from '@chatbotkit/nextauth'
export default NextAuth({
providers: [
ChatBotKitEmailProvider({
async sendVerificationRequest({ identifier, token }) {
// Send email with verification token to the user
await sendEmail({
to: identifier,
subject: 'Sign in to your account',
text: `Your verification code is: ${token}`,
})
},
}),
],
// ... other NextAuth configuration
})
A NextAuth.js email provider configured for passwordless authentication with ChatBotKit.
This provider implements a passwordless email authentication flow using secure 6-character verification codes instead of magic links. It's designed to work seamlessly with the ChatBotKit Partner API and provides a user-friendly authentication experience.
Problem It Solves
When building applications with ChatBotKit, you typically need to manage two separate user systems: one for your application authentication and another for ChatBotKit sub-accounts. This creates unnecessary complexity and maintenance overhead.
With this provider, you can eliminate your own authentication system entirely.
Instead of building and maintaining separate user management infrastructure, you rely solely on the partner accounts created within ChatBotKit. This means:
This approach is ideal for applications that exist primarily to provide a user interface for ChatBotKit functionality, allowing you to leverage ChatBotKit's Partner API as your complete user management and authentication backend.
Overview
The ChatBotKitEmailProvider generates cryptographically secure 6-character hexadecimal verification tokens (e.g., "a3f9c2") that are sent to users via email. These tokens have a 15-minute validity period by default, providing a balance between security and usability.
Unlike traditional magic link providers, this approach allows users to manually enter a short code, which is particularly useful for:
Security Features
crypto.getRandomValues()for cryptographic securityImplementation Requirements
You must implement the
sendVerificationRequestcallback to send verification codes to users. The default implementation only logs to console for development purposes.