Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(adapter-dynamodb): extend schema options #11463

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

DylanLacey
Copy link

@DylanLacey DylanLacey commented Jul 26, 2024

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.

🧢 Checklist

  • Documentation
  • Tests
  • Ready to be merged

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.

`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.

`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.
@DylanLacey DylanLacey requested review from 0ubbe and ndom91 as code owners July 26, 2024 14:24
Copy link

vercel bot commented Jul 26, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
auth-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 27, 2025 4:51am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
next-auth-docs ⬜️ Ignored (Inspect) Visit Preview Jan 27, 2025 4:51am

Copy link

vercel bot commented Jul 26, 2024

@DylanLacey is attempting to deploy a commit to the authjs Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions bot added adapters Changes related to the core code concerning database adapters dynamodb @auth/dynamodb-adapter labels Jul 26, 2024
@ndom91 ndom91 changed the title <feat>[adapter-dynamodb]: Extend Schema Options feat(adapter-dynamodb): extend schema options Sep 22, 2024
Copy link

stale bot commented Jan 21, 2025

It looks like this issue did not receive any activity for 60 days. It will be closed in 7 days if no further activity occurs. If you think your issue is still relevant, commenting will keep it open. Thanks!

@stale stale bot added the stale Did not receive any activity for 60 days label Jan 21, 2025
@DylanLacey
Copy link
Author

Hey folks, this is still relevant; Is there something I can do to help make it easier to get a trial deployment run, besides updating to remove the merge conflicts?

@stale stale bot removed the stale Did not receive any activity for 60 days label Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
adapters Changes related to the core code concerning database adapters dynamodb @auth/dynamodb-adapter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant