<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/better-auth-in-astro-on-cloudflare-workers-jdbjvzagk" -->

---
title: Better Auth in Astro on Cloudflare Workers | daily.dev
description: A practical guide to integrating Better Auth into an Astro SSR app running on Cloudflare Workers with a D1 SQLite database. Covers creating an auth factory...
canonical: https://daily.dev/posts/better-auth-in-astro-on-cloudflare-workers-jdbjvzagk
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Better Auth in Astro on Cloudflare Workers | daily.dev
og:description: A practical guide to integrating Better Auth into an Astro SSR app running on Cloudflare Workers with a D1 SQLite database. Covers creating an auth factory...
og:url: https://daily.dev/posts/better-auth-in-astro-on-cloudflare-workers-jdbjvzagk
og:image: https://api.daily.dev/og/posts/jdBjVZaGk.png
og:image:alt: Better Auth in Astro on Cloudflare Workers
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Better Auth in Astro on Cloudflare Workers

**[Flavio Copes](https://daily.dev/sources/flaviocopes)** · 4 min read · 0 upvotes · 0 comments

## Summary

A practical guide to integrating Better Auth into an Astro SSR app running on Cloudflare Workers with a D1 SQLite database. Covers creating an auth factory function using the Drizzle adapter, setting up a single catch-all API route for all auth endpoints, reading session data in Astro middleware, handling a cookie-copying gotcha when redirecting after sign-in, and adding GitHub OAuth. The setup avoids Node.js dependencies, making it compatible with the workerd runtime.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://flaviocopes.com/better-auth-astro-cloudflare>

## Similar posts on daily.dev

- [Astro SSR with D1 and Drizzle ORM](https://daily.dev/posts/astro-ssr-with-d1-and-drizzle-orm-mmodl4htl) · Flavio Copes · 0 upvotes · 0 comments
- [Simplified Authentication with Better Auth](https://daily.dev/posts/simplified-authentication-with-better-auth-weaj84lid) · Telerik · 0 upvotes · 0 comments
- [Better Auth: an introduction](https://daily.dev/posts/better-auth-an-introduction-uxcidt0we) · Flavio Copes · 0 upvotes · 0 comments
- [Better Auth: Framework-Agnostic Authentication Solution for TypeScript Apps](https://daily.dev/posts/better-auth-framework-agnostic-authentication-solution-for-typescript-apps-rqmyklhoe) · Syncfusion · 8 upvotes · 1 comments
- [How to Build a Headless WordPress Frontend with Astro SSR on Cloudflare Pages](https://daily.dev/posts/how-to-build-a-headless-wordpress-frontend-with-astro-ssr-on-cloudflare-pages-30hassk3l) · freeCodeCamp · 3 upvotes · 0 comments

---

Tags: [#authentication](https://daily.dev/tags/authentication), [#cloudflare](https://daily.dev/tags/cloudflare), [#astro](https://daily.dev/tags/astro), [#drizzle](https://daily.dev/tags/drizzle)

[View this post on daily.dev](https://daily.dev/posts/better-auth-in-astro-on-cloudflare-workers-jdbjvzagk)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Better Auth in Astro on Cloudflare Workers","url":"https://daily.dev/posts/better-auth-in-astro-on-cloudflare-workers-jdbjvzagk","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/better-auth-in-astro-on-cloudflare-workers-jdbjvzagk"},"datePublished":"2026-07-16T07:39:20.219Z","dateModified":"2026-07-16T07:39:39.636Z","description":"A practical guide to integrating Better Auth into an Astro SSR app running on Cloudflare Workers with a D1 SQLite database. Covers creating an auth factory...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/907c6c028f107fad7d0379f1571dde35?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/907c6c028f107fad7d0379f1571dde35?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Flavio Copes","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Flavio Copes","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/1f2dbd275797411bbd37bfdaaf0951a9","url":"https://daily.dev/sources/flaviocopes"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/better-auth-in-astro-on-cloudflare-workers-jdbjvzagk","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"authentication,cloudflare,astro,drizzle","timeRequired":"PT4M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Flavio Copes","item":"https://daily.dev/sources/flaviocopes"},{"@type":"ListItem","position":3,"name":"Better Auth in Astro on Cloudflare Workers"}]}
```

