GithubHelp home page GithubHelp logo

lucia-adapter-dynamodb's Introduction

DynamoDB Adapter for Lucia

Database Adapter for DynamoDB.

The adapter uses aws-sdk v3.

Installation

N.B. this package is not yet published on npm

pnpm install lucia-adapter-dynamodb

OR

yarn add lucia-adapter-dynamodb

OR

npm install lucia-adapter-dynamodb

Usage

It requires two parameters:

  • a document client (used to configure the connection to dynamodb, set credentials/region etc.)
  • a table name

For the document client, be sure to pass a reference to a DynamoDBDocument from @aws-sdk/lib-dynamodb, NOT a DynamoDBClient from @aws-sdk/client-dynamodb (DynamoDBDocument is an abstraction which handles automatic marshalling/unmarshalling of data in to JSON format).

import { adapter } from "lucia-adapter-dynamodb";
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocument } from "@aws-sdk/lib-dynamodb";

const client = new DynamoDBClient({ region, credentials });
const documentClient = DynamoDBDocument.from(client);

export const auth = lucia({
  adapter: adapter({ documentClient, table: "MyAuthTable" }),
});

DynamoDB Table schema

This adapter requires a Table with:

  • a composite primary key consisting of a pk and sk field
  • a global secondary index with the name gsi1
  • GSI primary key with the fields gsi1pk and gsi1sk

You can use the adapter with an existing table if this matches your schema. If not, it is recommended (for now) to use a new Table dedicated for Lucia auth.

N.B. In the future, I may add a configuration option to choose the pk/sk/gsi attribute names.

Example DynamoDB Table

Here is an example of a Table defined using SST:

const authTable = new Table(stack, "MyAuthTable", {
  fields: {
    pk: "string",
    sk: "string",
    gsi1pk: "string",
    gsi1sk: "string",
  },
  primaryIndex: { partitionKey: "pk", sortKey: "sk" },
  globalIndexes: {
    gsi1: { partitionKey: "gsi1pk", sortKey: "gsi1sk" },
  },
});

lucia-adapter-dynamodb's People

Contributors

r-moore avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.