fix: use pk and sk from DynamoDB adapter options when deleting session
☕️ Reasoning
The function deleteSession in the DynamoDB adapter fails when using a custom partition key (PK) and sort key (SK) attribute name, because the custom PK and SK doesn't get used.
A ValidationException occurs because the PK and SK attribute name is incorrect.
[next-auth][error][adapter_error_deleteSession]
https://next-auth.js.org/errors#adapter_error_deletesession The number of conditions on the keys is invalid {
message: 'The number of conditions on the keys is invalid',
stack: 'ValidationException: The number of conditions on the keys is invalid\n' +
' at throwDefaultError (/home/arvl/src/nextauth-bug-repro-dynamodb-delete-session/node_modules/.pnpm/@[email protected]/node_modules/@smithy/smithy-client/dist-cjs/default-error-handler.js:8:22)\n' +
' at /home/arvl/src/nextauth-bug-repro-dynamodb-delete-session/node_modules/.pnpm/@[email protected]/node_modules/@smithy/smithy-client/dist-cjs/default-error-handler.js:18:39\n' +
' at de_DeleteItemCommandError (/home/arvl/src/nextauth-bug-repro-dynamodb-delete-session/node_modules/.pnpm/@[email protected]/node_modules/@aws-sdk/client-dynamodb/dist-cjs/protocols/Aws_json1_0.js:741:20)\n' +
' at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n' +
' at async /home/arvl/src/nextauth-bug-repro-dynamodb-delete-session/node_modules/.pnpm/@[email protected]/node_modules/@smithy/middleware-serde/dist-cjs/deserializerMiddleware.js:7:24\n' +
' at async /home/arvl/src/nextauth-bug-repro-dynamodb-delete-session/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]/node_modules/@aws-sdk/lib-dynamodb/dist-cjs/baseCommand/DynamoDBDocumentClientCommand.js:26:34\n' +
' at async /home/arvl/src/nextauth-bug-repro-dynamodb-delete-session/node_modules/.pnpm/@[email protected]/node_modules/@aws-sdk/middleware-signing/dist-cjs/awsAuthMiddleware.js:14:20\n' +
' at async /home/arvl/src/nextauth-bug-repro-dynamodb-delete-session/node_modules/.pnpm/@[email protected]/node_modules/@smithy/middleware-retry/dist-cjs/retryMiddleware.js:27:46\n' +
' at async /home/arvl/src/nextauth-bug-repro-dynamodb-delete-session/node_modules/.pnpm/@[email protected]/node_modules/@aws-sdk/middleware-logger/dist-cjs/loggerMiddleware.js:7:26\n' +
' at async deleteSession (file:///home/arvl/src/nextauth-bug-repro-dynamodb-delete-session/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]/node_modules/@auth/dynamodb-adapter/index.js:410:25)',
name: 'ValidationException'
}
The fix is quite simple: make the function use the PK and SK from the config, so that this error doesn't occur.
🧢 Checklist
- [x] Documentation (N/A)
- [ ] Tests
- [x] Ready to be merged
🎫 Affected issues
Please scout and link issues that might be solved by this PR.
Fixes: https://github.com/nextauthjs/next-auth/issues/7973
📌 Resources
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 | Aug 23, 2023 8:14am |
1 Ignored Deployment
| Name | Status | Preview | Comments | Updated (UTC) |
|---|---|---|---|---|
| next-auth-docs | ⬜️ Ignored (Inspect) | Visit Preview | Aug 23, 2023 8:14am |
@arvl130 is attempting to deploy a commit to the authjs Team on Vercel.
A member of the Team first needs to authorize it.
Any progress made towards getting this merged, It's very annoying if you already have a custom partitionKey and SortKey and you're fix does indeed work perfectly
I don't know if there are guidelines but currently only @ndom91 is against the PR but it looks like they may not be free lately given commit history and it might better to add @balazsorban44 or @ThangHuuVu who appear to have been more active lately (Apologies if I missed something from the contributing guidelines or Nico was automatically assigned and you can't add reviewers)