[SDK-3557] Refactor session lifecycle #787
Merged
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.
📋 Changes
Changed the cookie writing behaviour from lazy (at the end of the request) to eager (when it's first accessed and the session is rolling and every-time it's updated).
This has enabled us to:
on-headers
dependency (which doesn't play well with Next.js server and doesn't work at all with Next.js middleware)getServerSideProps
wrapper and removed the need for an API route wrapper)updateUser
methodAt a cost of potentially higher overhead when updating the session multiple times in the request, because multiple calls to
updateUser
will cause multiple cookie serialisation (encryption) attempts (but multiple reads will stay the same).In order to do this we've needed to:
set-cookie
headerupdateUser
methodon-headers
📎 References
see #668 #425 #616 #524
🎯 Testing
https://github.com/auth0/nextjs-auth0/blob/54cd48f1e1cb78eb37b700f39f4da826a5683c1a/tests/session/update-user.test.ts