Confused: Astro on Cloudflare Workers - Accessing DOs & Env for Auth (Coming from VPS/SQLite)

I'm working on porting an Astro project with authentication from a traditional VPS/SQLite setup to Cloudflare Workers, and I'm feeling a bit lost on how to correctly access Cloudflare features like Durable Objects (DOs) and environment variables/secrets from within my Astro server-side code. On a VPS, I'd just connect to SQLite and read environment variables directly. With Cloudflare Workers: Accessing Bindings: How exactly does my Astro code (e.g., in an API route src/pages/api/auth/login.ts or a helper function in src/lib/auth.ts) get a reference to my Durable Object binding (defined in wrangler.toml) or environment secrets? I've seen context.locals.runtime.env, but I'm unsure if this is the right way for everything. Good Project Structure: Where is the "right" place to put: The Durable Object class definition itself? Helper functions that interact with the DO (e.g., for creating a session, fetching a user)? Code that needs to access bound secrets (like an API key for better-auth)? D1 vs. DO Storage for Auth: For better-auth which might traditionally use SQLite, should I be aiming to use D1 for user data and DOs primarily for session state management, or can DO storage handle more? I'm trying to integrate better-auth and need to store/retrieve user and session data using Cloudflare's infrastructure. Any pointers, examples, or best practices on structuring this within an Astro project for Cloudflare Workers would be massively appreciated! I'm just a bit overwhelmed trying to connect all the Cloudflare pieces within the Astro framework.
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?