-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Sessions API #12441
Sessions API #12441
Conversation
🦋 Changeset detectedLatest commit: c43ed43 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
* feat: add session config * chore: add session config docs * Fix * Expand doc * Handle schema * Remove example * Format * Lock * Fix schema * Update packages/astro/src/types/public/config.ts Co-authored-by: Sarah Rainsberger <[email protected]> * Update packages/astro/src/types/public/config.ts Co-authored-by: Sarah Rainsberger <[email protected]> * Add link to Sessions RFC in config.ts * Move session into experimental --------- Co-authored-by: Sarah Rainsberger <[email protected]>
* feat: add session object * Add tests and fix logic * Fixes * Allow string as cookie option * wip: implement sessions (#12478) * feat: implement sessions * Add middleware * Action middleware test * Support URLs * Remove comment * Changes from review * Update test * Ensure test file is run
91da474
to
6f8f546
Compare
a9ec98f
to
6763eff
Compare
* fix: use virtual import for storage drivers * Don't try to resolve anythign in build * Fix test * Polyfill node:url * Handle custom drivers directly * No need for path * Update packages/astro/src/core/session.ts Co-authored-by: Emanuele Stoppa <[email protected]> --------- Co-authored-by: Emanuele Stoppa <[email protected]>
6878139
to
3e53f85
Compare
b7b1125
to
daa94b5
Compare
!preview sessions |
Snapshots have been released for the following packages:
Publish Log
Build Log
|
* wip * wip * Export manifest in middleware * Changeset conf * Pass session to edge middleware * Support initial session data * Persist edge session on redirect * Remove middleware-related changes * Refactor * Remove vite plugin * Format * Simplify import * Handle missing config * Handle async resolution
* feat(sessions): implement ttl and flash * chore: add unit tests * Make set arg an object * Add more tests * Add test fixtures * Add comment
!preview sessions |
Snapshots have been released for the following packages:
Publish Log
Build Log
|
!preview sessions |
Snapshots have been released for the following packages:
Publish Log
Build Log
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is blocked because it contains a minor
changeset. A reviewer will merge this at the next release if approved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking great @ascorbic ! Left some tiny thoughts on the changeset for your consideration! 🙌
Co-authored-by: Sarah Rainsberger <[email protected]>
}, | ||
} | ||
``` | ||
If you are deploying to a serverless environment, you can use drivers such as `redis` or `netlifyBlobs` or `cloudflareKV` and optionally pass additional configuration options. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you are deploying to a serverless environment, you can use drivers such as `redis` or `netlifyBlobs` or `cloudflareKV` and optionally pass additional configuration options. | |
If you are deploying to a serverless environment, you can use drivers such as `redis` or `netlify-blobs` or `cloudflare-kv` and optionally pass additional configuration options. |
PLACEHOLDER REMINDER COMMENT in case the driver syntax changes before this is merged/released!
(This is currently correct, but the day's not over yet!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving for docs, but have left one comment to remind us to circle back and update if the driver names change!
API Bashing
Thanks for trying the experimental sessions API. Here's how to get set up.
Setup
Create a project as normal, or use an existing one:
Install the experimental
astro
release:Sessions require SSR, so you should add an adapter (though you can test in dev without one):
# or your choice of adapter npm run astro add node
Configure the session config:
You can try other drivers supported by Unstorage. Specify them using the camel-cased name:
Note
For some drivers you may need to install additional node modules. See the Unstorage driver docs for details.
For more details of configuration options, see the RFC.
Usage
The session object is available in server-rendered pages, API endpoints, actions and (non-edge) middleware.
Usage in an Astro component
Usage in an API endpoint:
Usage in an Action:
Usage in middleware.
Note
Edge middleware is not currently supported
For the full runtime API, see the RFC
What to test
Testing sites deployed to real hosts is particularly helpful. Also, if possible test drivers beyond the
fs
Node driver.Comment on this PR with your bugs and feedback on the API
Testing
Docs