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: Add DynamoDB as a Bundled Store for Sessions #87

Merged
merged 8 commits into from
Sep 23, 2024

Conversation

7nohe
Copy link
Contributor

@7nohe 7nohe commented Sep 16, 2024

πŸ”— Linked issue

https://github.com/orgs/adonisjs/discussions/4710

❓ Type of change

  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Added DynamoDB as a bundled store option for session management.
In order to use this option, you need to prepare a DynamoDB table, and session data is read and written using the DynamoDB client.

For testing, I have used DynamoDB Local.
Additionally, I have prepared a demo application that uses DynamoDB as a store for sessions.
You cannot try the real DynamoDB server without creating an AWS account, but this repository includes code that creates a DynamoDB table just by running AWS CDK. You should be able to try it right away by simply creating an IAM user to execute the cdk deploy command.

Here is the Laravel code I used as a reference for the implementation.
https://github.com/laravel/framework/blob/11.x/src/Illuminate/Cache/DynamoDbStore.php

πŸ“ Checklist

@thetutlage
Copy link
Member

Interesting stuff!

@thetutlage
Copy link
Member

Hello @7nohe The tests are failing on the CI. Can you please take a look why?

@7nohe
Copy link
Contributor Author

7nohe commented Sep 17, 2024

Hello @7nohe The tests are failing on the CI. Can you please take a look why?

Sure. It seems like we will probably need a DynamoDB local environment on the CI.

@7nohe
Copy link
Contributor Author

7nohe commented Sep 17, 2024

@thetutlage
I have set up a DynamoDB Local environment on the CI, so the tests should now pass.

@thetutlage thetutlage self-requested a review September 21, 2024 18:07
@thetutlage thetutlage added the Type: Feature Request Request to add a new feature to the package label Sep 21, 2024
Copy link
Member

@thetutlage thetutlage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks neat!

Comment on lines 164 to 166
config.keyAttribute,
config.valueAttribute,
config.expiresAtAttribute
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any legit reasons for allowing to customize the attribute names?

I get it provides flexibility, but if the names are hardcoded, do we have any downsides?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thetutlage
Since the keyAttribute must be defined when creating a DynamoDB table, flexibility is necessary to allow it to be overwritten later.
As for the valueAttribute and expiresAtAttribute, to be honest, I can’t think of many cases where hardcoding them would cause issues.
I referred to Laravel’s implementation, and perhaps there may be cases where you want to share the session table with an already existing application.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. So let's hardcode valueAttribute and the expiresAtAttribute attribute and let's see how it goes. We can always make them attributes configurable later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thetutlage
I have hardcoded the valueAttribute and expiresAtAttribute. I have also updated the documentation.

@thetutlage
Copy link
Member

I have created this PR which will fix failing tests unrelated to your PR. 7nohe#3

tests: fix tests to be more resillient with core changes
@7nohe
Copy link
Contributor Author

7nohe commented Sep 23, 2024

I have created this PR which will fix failing tests unrelated to your PR. 7nohe#3

Merged!

@thetutlage thetutlage merged commit f9a2f7b into adonisjs:develop Sep 23, 2024
6 checks passed
@thetutlage
Copy link
Member

Thanks a ton @7nohe for taking out time and working on it. I will cut a release in coming days and will notify you

@7nohe
Copy link
Contributor Author

7nohe commented Sep 23, 2024

@thetutlage
Thank you for your help. Once it’s released, I plan to use this feature in a real project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature Request Request to add a new feature to the package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants