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

doc(sesison): add support for DynamoDB store #148

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion content/docs/basics/session.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ You can manage user sessions inside your AdonisJS application using the `@adonis

- `redis`: The session data is stored inside a Redis database. The redis store is recommended for apps with large volumes of session data and can scale to multi-server deployments.

- `dynamodb`: The session data is stored inside an Amazon DynamoDB table. The DynamoDB store is suitable for applications that require a highly scalable and distributed session store, especially when the infrastructure is built on AWS.

- `memory`: The session data is stored within a global memory store. The memory store is used during testing.

Alongside the inbuilt backend stores, you can also create and [register custom session stores](#creating-a-custom-session-store).
Expand Down Expand Up @@ -203,6 +205,17 @@ export default defineConfig({
redis: stores.redis({
connection: 'main'
})

dynamodb: stores.dynamodb({
clientConfig: {
// DynamoDB client config
// See: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-dynamodb/Interface/DynamoDBClientConfig/
// You can also set credentials using the environment variables `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`.
// Also, you can set the region using the environment variable `AWS_REGION`.
},
tableName: 'Session', // The table name to store the sessions. The default is `Session`.
keyAttribute: 'key', // The attribute name for the session id, default is `key`.
}),
}
// highlight-end
})
Expand Down Expand Up @@ -250,14 +263,26 @@ Make sure to first install and configure the [@adonisjs/redis](../database/redis

</dd>

<dt>

stores.dynamodb

</dt>

<dd>

Define the configuration for the `dynamodb` store. The method accepts the `clientConfig`, `tableName` and `keyAttribute` properties.

</dd>

</dl>

---

### Updating environment variables validation
If you decide to use session stores other than the default one, make sure to also update the environment variables validation for the `SESSION_DRIVER` environment variable.

We configure the `cookie` and the `redis` stores in the following example. Therefore, we should also allow the `SESSION_DRIVER` environment variable to be one of them.
We configure the `cookie`, the `redis`, and the `dynamodb` stores in the following example. Therefore, we should also allow the `SESSION_DRIVER` environment variable to be one of them.

```ts
import { defineConfig, stores } from '@adonisjs/session'
Expand Down