Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yanthomasdev
Copy link
Member

@yanthomasdev yanthomasdev commented May 17, 2025

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!)

@yanthomasdev yanthomasdev added the improve or update documentation Enhance / update existing documentation (e.g. add example, improve description, update for changes) label May 17, 2025
Copy link

netlify bot commented May 17, 2025

Deploy Preview for astro-docs-2 ready!

Name Link
🔨 Latest commit 610e22c
🔍 Latest deploy log https://app.netlify.com/projects/astro-docs-2/deploys/6828e85d96ab620008f16e59
😎 Deploy Preview https://deploy-preview-11708--astro-docs-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@astrobot-houston
Copy link
Contributor

Lunaria Status Overview

🌕 This pull request will trigger status changes.

Learn more

By default, every PR changing files present in the Lunaria configuration's files property will be considered and trigger status changes accordingly.

You can change this by adding one of the keywords present in the ignoreKeywords property in your Lunaria configuration file in the PR's title (ignoring all files) or by including a tracker directive in the merged commit's description.

Tracked Files

File Note
en/guides/integrations-guide/cloudflare.mdx Source changed, localizations will be marked as outdated.
Warnings reference
Icon Description
🔄️ The source for this localization has been updated since the creation of this pull request, make sure all changes in the source have been applied.

Copy link
Member

@sarah11918 sarah11918 left a 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.
Copy link
Contributor

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

Copy link
Member Author

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?

Suggested change
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.

Copy link
Member

@alexanderniebuhr alexanderniebuhr May 21, 2025

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.

Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improve or update documentation Enhance / update existing documentation (e.g. add example, improve description, update for changes)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants