Accessing D1 outside of a request in an Astro app

I'm using astro-auth [1] in an on-demand rendered app, using adapter-cloudflare [2] to deploy to Cloudflare workers. My auth.config.ts file exists outside of a request, so I can't access my D1 database (context.locals.runtime.env.DB) Is it possible to access the Cloudflare runtime outside of a request? If not, any tips on how to initialize astro-auth in middleware? [1] https://github.com/nowaythatworked/auth-astro [2] https://docs.astro.build/en/guides/integrations-guide/cloudflare/
GitHub
GitHub - nowaythatworked/auth-astro: Community maintained Astro int...
Community maintained Astro integration of @auth/core - nowaythatworked/auth-astro
Docs
@astrojs/cloudflare
Learn how to use the @astrojs/cloudflare SSR adapter to deploy your Astro project.
1 Reply
xoxo
xoxo2mo ago
Have you found a solution? One way to workaround is to put your secrets to .env . It bakes the values to build artefact, which is not ideal. I am moving to pages/workers and facing similar issues, but for auth specifically I use https://www.better-auth.com it actually allows to specify db and social providers secrets within request context.
Better Auth
Better Auth
The most comprehensive authentication library for TypeScript.

Did you find this page helpful?