DynamoDB adapter for NextAuth.js
- supports passwordless email sign in
- saves user object to users table
- stateless sessions only
- AWS SDK v3 client
Database sessions are not implemented, this adapter relies on usage of JSON Web Tokens for stateless session management.
This package is not supported by NextAuth.js, visit the official AWS DynamoDB Adapter for advanced features and community support.
Install the next-auth package.
$ yarn add next-auth-dynamodb-adapter
$ npm install next-auth-dynamodb-adapter
import NextAuth from 'next-auth';
import Providers from 'next-auth/providers'
import {DynamoDBAdapter} from 'next-auth-dynamodb-adapter';
export default NextAuth({
// Configure one or more authentication providers.
providers: [
// ...add providers here
],
session: {
// Use JSON Web Tokens for session instead of database sessions.
jwt: true,
},
adapter: new DynamoDBAdapter(
{
region: process.env.AWS_REGION,
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
},
},
{
usersTable: 'Users',
verificationRequestsTable: 'VerificationRequests',
}
),
// Turn debug logger off for the production environment, the output might contain user information and verification tokens.
debug: process.env.NODE_ENV !== 'production'
})
DynamoDBAdapter
class instance takes two initialization objects:
new DynamoDBAdapter(DynamoDBClientConfig, TableNameOptions)
DynamoDB client configuration object.
AWS account passed to the credentials
property must have read/write access to TableNameOptions
tables.
Specify a table name (String). Table with that name and correct partition key must exist in your AWS account.
- optional
- partition key:
id
(String) - description: stores user object after successful sign in.
- optional
- partition key:
email
(String) - description: stores passwordless email sign in verification requests, one token for one email address at a time.
MIT