Skip to content

Commit 6437363

Browse files
authored
feat(cli): enhance auth config and README with deploy guidance (#587)
1 parent b167db0 commit 6437363

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

apps/cli/src/helpers/core/create-readme.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ ${
128128
: ""
129129
}
130130
131+
${generateWorkersRuntimeNotes(runtime)}
132+
131133
${generateDeploymentCommands(packageManagerRunCmd, webDeploy, serverDeploy)}
132134
133135
## Project Structure
@@ -653,6 +655,29 @@ function generateScriptsList(
653655
return scripts;
654656
}
655657

658+
function generateWorkersRuntimeNotes(runtime: Runtime) {
659+
if (runtime !== "workers") {
660+
return "";
661+
}
662+
663+
return `
664+
## Before Deploying to Cloudflare
665+
666+
When you are ready to deploy your app to Cloudflare Workers, you'll have to make a couple changes.
667+
- Change your url environment variables to match your \`*.workers.dev\` domains generated by Cloudflare:
668+
669+
\`\`\`bash
670+
# apps/web/.env
671+
SERVER_URL={your-production-server-domain}
672+
673+
# apps/server/.env
674+
CORS_ORIGIN={your-production-web-domain}
675+
BETTER_AUTH_URL={your-production-server-domain}
676+
\`\`\`
677+
- In \`apps/server/lib/auth.ts\`, uncomment the \`session.cookieCache\` and \`advanced.crossSubDomainCookies\` sections and replace \`<your-workers-subdomain>\` with your actual workers subdomain. These settings are required to ensure cookies are transferred properly between your web and server domains.
678+
`;
679+
}
680+
656681
function generateDeploymentCommands(
657682
packageManagerRunCmd: string,
658683
webDeploy?: string,

apps/cli/templates/auth/better-auth/server/base/src/lib/auth.ts.hbs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,13 @@ export const auth = betterAuth<BetterAuthOptions>({
164164
emailAndPassword: {
165165
enabled: true,
166166
},
167+
// uncomment cookieCache setting when ready to deploy to Cloudflare using *.workers.dev domains
168+
// session: {
169+
// cookieCache: {
170+
// enabled: true,
171+
// maxAge: 60,
172+
// },
173+
// },
167174
secret: env.BETTER_AUTH_SECRET,
168175
baseURL: env.BETTER_AUTH_URL,
169176
advanced: {
@@ -172,6 +179,12 @@ export const auth = betterAuth<BetterAuthOptions>({
172179
secure: true,
173180
httpOnly: true,
174181
},
182+
// uncomment crossSubDomainCookies setting when ready to deploy and replace <your-workers-subdomain> with your actual workers subdomain
183+
// https://developers.cloudflare.com/workers/wrangler/configuration/#workersdev
184+
// crossSubDomainCookies: {
185+
// enabled: true,
186+
// domain: "<your-workers-subdomain>",
187+
// },
175188
},
176189
{{#if (eq payments "polar")}}
177190
plugins: [

0 commit comments

Comments
 (0)