Manual Setup? Cannot run @better-auth/cli generate

This may become a bigger problem down the line as well, I am not sure. I am attempting to go through the initial setup. My app runs on Cloudflare workers, which does not have access to process.env. Instead I must pass the variable to it from a context.
export const auth = (DATABASE_URL: string) => {
return betterAuth({
database: drizzleAdapter(getDb({ DATABASE_URL }), {
provider: "pg",
})
});
}
export const auth = (DATABASE_URL: string) => {
return betterAuth({
database: drizzleAdapter(getDb({ DATABASE_URL }), {
provider: "pg",
})
});
}
Having this in my auth.ts causes this error when attempting to generate the user tables
❯ npx @better-auth/cli generate
2025-06-12T01:21:44.064Z ERROR [Better Auth]: [#better-auth]: Couldn't read your auth config. Error: DATABASE_URL environment variable is required
❯ npx @better-auth/cli generate
2025-06-12T01:21:44.064Z ERROR [Better Auth]: [#better-auth]: Couldn't read your auth config. Error: DATABASE_URL environment variable is required
I think I would rather create the schema file where I want to anyway. Is the schema we need to create documented anywhere?
12 Replies
fres
fres3mo ago
Hi did u find a way to solve this? I am facing the same error. Thanks
TechSquidTV
TechSquidTVOP3mo ago
I didn't end up looking too closely. I'm currently planning on going back to Supabase auth for now
fres
fres3mo ago
After some consideration I decide to delegate the auth and user management (so only better auth) to a neon instance and the core data application to D1. It has some cons ofc, no fk with "user_id" and app level logic to handle relations with users. Dunno if it's the best options (I would like to try out D1), I'll test it for some times
TechSquidTV
TechSquidTVOP3mo ago
Id love to know how it goes. I also am looking at D1 for cost. I'm just not terribly confident in using it yet as they want smaller and more distributed databases, and right now my design is based on a large, single database. You're headed the direction I want to go though
daanish
daanish3mo ago
you can use .dev.vars file to store the variable generate types using
wrangler types --env local
wrangler types --env local
then import the env from cloudfare:workers module and use it like
import { env } from 'cloudflare:workers';
env.DATABASE_URL
import { env } from 'cloudflare:workers';
env.DATABASE_URL
fres
fres3mo ago
damn i didnt know that, I'll try it out but wait, this import will work in local only or also in prod? because I previously understood that you could access envs only via the Hono context by doing const app = new Hono<TYPE>(); where TYPE includes Bindings: CloudflareBindings;
daanish
daanish3mo ago
you i need to configure wrangler.jsonc
daanish
daanish3mo ago
Cloudflare Docs
Environment variables
You can add environment variables, which are a type of binding, to attach text strings or JSON values to your Worker.
fres
fres3mo ago
nvm bro, I just said smtng stupid tysm tho
daanish
daanish3mo ago
like this
{
"$schema": "node_modules/wrangler/config-schema.json",
"name": "hello",
"compatibility_date": "2025-05-01",
"compatibility_flags": ["nodejs_compat"],
"main": "./worker.ts",
"observability": {
"enabled": true,
},
"env": {
"local": {
"vars": {
"VITE_PUBLIC_BACKEND_URL": "http://localhost:8787",
"VITE_PUBLIC_APP_URL": "http://localhost:3000",
},
},
"staging": {
"vars": {
"VITE_PUBLIC_BACKEND_URL": "https://example.com",
"VITE_PUBLIC_APP_URL": "https://example.com",
},
},
"production": {
"vars": {
"VITE_PUBLIC_BACKEND_URL": "https://example.com",
"VITE_PUBLIC_APP_URL": "https://example.com",
},
},
},
}
{
"$schema": "node_modules/wrangler/config-schema.json",
"name": "hello",
"compatibility_date": "2025-05-01",
"compatibility_flags": ["nodejs_compat"],
"main": "./worker.ts",
"observability": {
"enabled": true,
},
"env": {
"local": {
"vars": {
"VITE_PUBLIC_BACKEND_URL": "http://localhost:8787",
"VITE_PUBLIC_APP_URL": "http://localhost:3000",
},
},
"staging": {
"vars": {
"VITE_PUBLIC_BACKEND_URL": "https://example.com",
"VITE_PUBLIC_APP_URL": "https://example.com",
},
},
"production": {
"vars": {
"VITE_PUBLIC_BACKEND_URL": "https://example.com",
"VITE_PUBLIC_APP_URL": "https://example.com",
},
},
},
}
don't add the vars here which are important. important should be stored in .dev.vars and by running the command you generate the types and use it
TechSquidTV
TechSquidTVOP3mo ago
heyy appreciate this ty
daanish
daanish3mo ago
ok

Did you find this page helpful?