This repository has been archived by the owner on Jul 17, 2022. It is now read-only.
fix(dynamo): Ensure expires attribute is stored as a UNIX timestamp [Take 2] #367
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Repeat of #366, targeted at
main
branchReasoning 💡
Hi! This is a small change compared to the number of words and tests I wrote!
This change applies to the DynamoDB adapter.
DynamoDB supports a "TTL" feature that automatically purges old items from the database if they are marked with a special attribute. The existing adapter docs suggest enabling this feature and setting it to use the
expires
attribute. This is a reasonable choice, because Next Auth already uses theexpires
property on Sessions and VerificationTokens for basically the same purpose.However, as clarified in the AWS docs, the special TTL attribute must be stored as a UNIX timestamp in seconds. I have fixed a bug in the DynamoDB adapter, which resulted in the
expires
attribute being stored as an ISO string, meaning that the TTL feature would not work for Next Auth Sessions and VerificationTokens. Following this PR, the TTL feature should work, because nowexpires
is stored as a numeric timestamp.I added some unit tests for the code that converts objects to and from the format saved in DynamoDB. Most of the tests were passing before this PR, but I thought it was worth adding them anyway. All the tests pass on my machine with these changes.
The code before I edited it appeared to convert
expires
between anumber
and astring
. However, so far as I can tell, theexpires
property onAdapterSession
andVerificationToken
is aDate
, so I think that code path was just being skipped entirely. I can confirm that, in my database, theexpires
attribute is in fact being stored as an ISO string. Paging @mathisobadia in case they know what the code was originally trying to do.Thanks :)
Checklist 🧢
[ ] DocumentationAffected issues 🎟
This is related to #252, but that issue was closed (possibly incorrectly? I don't know if this worked in a previous version!).