forked from withastro/astro
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip: experimental sessions * feat: adds session options (withastro#12450) * 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 <sarah@rainsberger.ca> * Update packages/astro/src/types/public/config.ts Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Add link to Sessions RFC in config.ts * Move session into experimental --------- Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Lock * feat: prototype session support (withastro#12471) * feat: add session object * Add tests and fix logic * Fixes * Allow string as cookie option * wip: implement sessions (withastro#12478) * feat: implement sessions * Add middleware * Action middleware test * Support URLs * Remove comment * Changes from review * Update test * Ensure test file is run * ci: changeset base * ci: exit from changeset pre mode * Lockfile * Update base * fix: use virtual import for storage drivers (withastro#12520) * 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 <my.burning@gmail.com> --------- Co-authored-by: Emanuele Stoppa <my.burning@gmail.com> * Fix jsdoc * fix: set default storage path * Update changeset config for now * Revert config workaround * Lock * Remove unneeded ts-expect-error directive * fix: [sessions] import storage driver in manifest (withastro#12654) * 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 * Lockfile * feat(sessions): implement ttl and flash (withastro#12693) * feat(sessions): implement ttl and flash * chore: add unit tests * Make set arg an object * Add more tests * Add test fixtures * Add comment * Remove session.flash for now (withastro#12745) * Changeset * Apply suggestions from code review Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com> --------- Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> Co-authored-by: Emanuele Stoppa <my.burning@gmail.com> Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com>
- Loading branch information
1 parent
3dc02c5
commit b4fec3c
Showing
27 changed files
with
2,174 additions
and
520 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
'astro': minor | ||
--- | ||
|
||
Adds experimental session support | ||
|
||
Sessions are used to store user state between requests for server-rendered pages, such as login status, shopping cart contents, or other user-specific data. | ||
|
||
```astro | ||
--- | ||
export const prerender = false; // Not needed in 'server' mode | ||
const cart = await Astro.session.get('cart'); | ||
--- | ||
<a href="/checkout">🛒 {cart?.length ?? 0} items</a> | ||
``` | ||
|
||
Sessions are available in on-demand rendered/SSR pages, API endpoints, actions and middleware. To enable session support, you must configure a storage driver. | ||
|
||
If you are using the Node.js adapter, you can use the `fs` driver to store session data on the filesystem: | ||
|
||
```js | ||
// astro.config.mjs | ||
{ | ||
adapter: node({ mode: 'standalone' }), | ||
experimental: { | ||
session: { | ||
// Required: the name of the Unstorage driver | ||
driver: "fs", | ||
}, | ||
}, | ||
} | ||
``` | ||
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. | ||
|
||
For more information, including using the session API with other adapters and a full list of supported drivers, see [the docs for experimental session support](https://docs.astro.build/en/reference/experimental-flags/sessions/). For even more details, and to leave feedback and participate in the development of this feature, [the Sessions RFC](https://github.com/withastro/roadmap/pull/1055). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.