Optionaloptions: EmailUserConfigimport NextAuth from 'next-auth'
import {
ChatBotKitContactAdapter,
ChatBotKitContactEmailProvider,
ContactMemoryStore,
} from '@chatbotkit/nextauth/contact'
export default NextAuth({
adapter: ChatBotKitContactAdapter({
secret: process.env.CHATBOTKIT_API_SECRET,
store: new ContactMemoryStore(),
autoCreateContact: true,
autoUpdateContact: true,
autoDeleteContact: false,
}),
providers: [
ChatBotKitContactEmailProvider({
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}`,
})
},
}),
],
session: {
strategy: 'jwt',
},
// ... other NextAuth configuration
})
A NextAuth.js email provider configured for passwordless authentication with ChatBotKit Contacts.
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 Contact API and provides a user-friendly authentication experience for contact-based authentication.
Problem It Solves
When building applications where users are managed as contacts within a single ChatBotKit account, you need an authentication mechanism that maps users to contacts rather than separate accounts. This provider enables passwordless authentication that integrates with the Contact adapter.
With this provider and the Contact adapter, you can:
Overview
The ChatBotKitContactEmailProvider 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.