next-auth icon indicating copy to clipboard operation
next-auth copied to clipboard

feat(adapter-dynamodb): extend schema options

Open DylanLacey opened this issue 6 months ago • 2 comments

This change allows for more flexibility when customising the schema used by the DynamoDB adapter. Specifically, it adds the ability to customize:

  • EntityTagName: The attribute name under which to store the type of the entity.
  • EntityTags: The value to use for each Entity type for the above attribute.
  • EntitySlugs: The slug which is prepended to each type's partition/sort key.

index.test.ts and format.test.ts were updated to reflect changes required to the format.from function.

custom_config.test.ts was added, which runs a full suite of the basic tests against both the existing customizations and those included in this PR.

💻 Example

EntityTags and EntitySlug are both of type DynamoDBEntityTypeOptions and can take an (optional, string) value for each type of entity the adapter stores:

const entityTags: DynamoDBEntityTypeOptions = {
    user: "AUTHUSER",
    account: "ACT",
    session: "SES",
    vt: "VT"
}

EntitySlug does not format the provided slugs in any way; If users wish to include a separator such as #, they need to include it.

☕️ Reasoning

Firstly, to increase the ability to integrate Auth.js with other systems. For instance , DynamoDBToolbox uses an attribute _et by default to type records.

Secondly, to give users more control in general. They may wish to disambiguate AuthJS User items from some extant User entity, or shorten ACCOUNT to ACNT.

Documentation was not added, as the documentation on the

🧢 Checklist

  • [X] Documentation
  • [X] Tests
  • [X] Ready to be merged

DylanLacey avatar Jul 26 '24 14:07 DylanLacey