Skip to content
This repository has been archived by the owner on Jul 23, 2022. It is now read-only.

Simple DynamoDB adapter for NextAuth.js focused on stateless sessions.

License

Notifications You must be signed in to change notification settings

michalsvorc/next-auth-dynamodb-adapter

Repository files navigation

DynamoDB adapter for NextAuth.js

Overview

Features

Database sessions

Database sessions are not implemented, this adapter relies on usage of JSON Web Tokens for stateless session management.

Notice

This package is not supported by NextAuth.js, visit the official AWS DynamoDB Adapter for advanced features and community support.

Installation

Base package

Install the next-auth package.

Adapter

yarn

$ yarn add next-auth-dynamodb-adapter

npm

$ npm install next-auth-dynamodb-adapter

Usage

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'
})

Configuration

DynamoDBAdapter class instance takes two initialization objects:

new DynamoDBAdapter(DynamoDBClientConfig, TableNameOptions)

DynamoDBClientConfig

DynamoDB client configuration object.

AWS account passed to the credentials property must have read/write access to TableNameOptions tables.

TableNameOptions

Specify a table name (String). Table with that name and correct partition key must exist in your AWS account.

usersTable

  • optional
  • partition key: id (String)
  • description: stores user object after successful sign in.

verificationRequestsTable

  • optional
  • partition key: email (String)
  • description: stores passwordless email sign in verification requests, one token for one email address at a time.

License

MIT

About

Simple DynamoDB adapter for NextAuth.js focused on stateless sessions.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published