-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Clarify usage of fs storage in Sessions with Cloudflare adapter #11708
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
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for astro-docs-2 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Lunaria Status Overview🌕 This pull request will trigger status changes. Learn moreBy default, every PR changing files present in the Lunaria configuration's You can change this by adding one of the keywords present in the Tracked Files
Warnings reference
|
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 looks fantastic @yanthomasdev 🫡
@@ -394,7 +394,9 @@ Creating a custom `public/_routes.json` will override the automatic generation. | |||
|
|||
The Astro [Sessions API](/en/guides/sessions/) allows you to easily store user data between requests. This can be used for things like user data and preferences, shopping carts, and authentication credentials. Unlike cookie storage, there are no size limits on the data, and it can be restored on different devices. | |||
|
|||
Astro automatically configures [Workers KV](https://developers.cloudflare.com/kv/) for session storage when using the Cloudflare adapter. Before using sessions, you need to create a KV namespace to store the data and configure a KV binding in your Wrangler config file. By default, Astro expects the KV binding to be named `SESSION`, but you can choose a different name if you prefer by setting the [`sessionKVBindingName`](#sessionkvbindingname) option in the adapter config. | |||
Astro automatically configures [Workers KV](https://developers.cloudflare.com/kv/) for session storage when using the Cloudflare adapter in production. To avoid mistakes that could compromise your data or cause unexpected bills, the filesystem storage will be used during local development by default. |
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.
It's not to avoid mistakes. It's because we don't have access to KV when running in dev, because astro dev
doesn't use wrangler. The same applies to the Netlify adapter when running without the Netlify CLI
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.
Right, I assumed KV would be somewhat available as part of the Cloudflare runtime injected by the adapter, and we just replaced that with the fs driver for safety.
Maybe this works?
Astro automatically configures [Workers KV](https://developers.cloudflare.com/kv/) for session storage when using the Cloudflare adapter in production. To avoid mistakes that could compromise your data or cause unexpected bills, the filesystem storage will be used during local development by default. | |
Astro automatically configures [Workers KV](https://developers.cloudflare.com/kv/) for session storage when using the Cloudflare adapter in production. During development, since Cloudflare KV cannot be accessed in the Astro dev server, the filesystem storage will be used instead. |
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.
@ascorbic You are right we don't have access to remote KV. But we do have access to Cloudflare's platformProxy
. We shouldn't use custom logic to use fs
, we should just rely on the local Proxy. I'll check the code and make sure to fix this.
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.
Thanks @alexanderniebuhr. That would be great.
Description (required)
When using the dev server with the Cloudflare adapter, you actually don't end up using the Cloudflare KV storage for sessions, but instead the filesystem storage.
Related issues & labels (optional)
Sibling core PR: withastro/astro#13817 (it doesn't depend on it to be merged!)