Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

refactor(web): use NODE_ENV instead of custom AUTH_MODE for auth branching

Generbfd8159b769c
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 2c15b39c9..e22e7203d 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -58,7 +58,7 @@ jobs:
cache: pnpm
- run: pnpm install --frozen-lockfile
- name: Create .dev.vars for local bindings
- run: printf 'BETTER_AUTH_SECRET=ci-e2e-secret\nBETTER_AUTH_URL=http://localhost:3000\nAUTH_MODE=password\n' > src/web/.dev.vars
+ run: printf 'BETTER_AUTH_SECRET=ci-e2e-secret\nBETTER_AUTH_URL=http://localhost:3000\n' > src/web/.dev.vars
- run: pnpm run db:migrate
- name: Start dev server
run: |
diff --git a/src/web/.dev.vars.example b/src/web/.dev.vars.example
index bc773a9ae..25661c053 100644
--- a/src/web/.dev.vars.example
+++ b/src/web/.dev.vars.example
@@ -17,7 +17,3 @@ GITHUB_CLIENT_SECRET=
# Google OAuth (https://console.cloud.google.com/apis/credentials)
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
-
-# Override wrangler.toml's AUTH_MODE=otp for local dev
-# "password" enables email+password auth, "otp" enables email OTP
-AUTH_MODE=password
diff --git a/src/web/cloudflare-env.d.ts b/src/web/cloudflare-env.d.ts
index e9f37d8ef..2c69f3667 100644
--- a/src/web/cloudflare-env.d.ts
+++ b/src/web/cloudflare-env.d.ts
@@ -5,7 +5,6 @@ declare namespace Cloudflare {
interface Env {
IMAGES: ImagesBinding;
ASSETS: Fetcher;
- AUTH_MODE: string;
WORKER_SELF_REFERENCE: Fetcher /* web */;
}
}
@@ -14,7 +13,7 @@ type StringifyValues<EnvType extends Record<string, unknown>> = {
[Binding in keyof EnvType]: EnvType[Binding] extends string ? EnvType[Binding] : string;
};
declare namespace NodeJS {
- interface ProcessEnv extends StringifyValues<Pick<Cloudflare.Env, "AUTH_MODE">> {}
+ interface ProcessEnv {}
}
// Begin runtime types
diff --git a/src/web/next.config.ts b/src/web/next.config.ts
index abf57a701..418e01721 100644
--- a/src/web/next.config.ts
+++ b/src/web/next.config.ts
@@ -1,28 +1,10 @@
import type { NextConfig } from "next";
import path from "node:path";
-import { readFileSync } from "node:fs";
-
-// Resolve AUTH_MODE for client bundles. Wrangler bindings are runtime-only,
-// so we read the value at build/dev time from .dev.vars (overrides) → wrangler.toml.
-function resolveVar(key: string): string | undefined {
- if (process.env[key]) return process.env[key];
- for (const file of [".dev.vars", "wrangler.toml"]) {
- try {
- const content = readFileSync(path.resolve(__dirname, file), "utf-8");
- const match = content.match(new RegExp(`^${key}\\s*=\\s*"?([^"\\n]*)"?`, "m"));
- if (match?.[1]) return match[1];
- } catch { /* file may not exist */ }
- }
- return undefined;
-}
const nextConfig: NextConfig = {
turbopack: {
root: path.resolve(__dirname, "../.."),
},
- env: {
- NEXT_PUBLIC_AUTH_MODE: resolveVar("AUTH_MODE") ?? "password",
- },
};
export default nextConfig;
diff --git a/src/web/src/app/(auth)/sign-in/page.tsx b/src/web/src/app/(auth)/sign-in/page.tsx
index 0221de826..650a0395b 100644
--- a/src/web/src/app/(auth)/sign-in/page.tsx
+++ b/src/web/src/app/(auth)/sign-in/page.tsx
@@ -21,7 +21,7 @@ import { SiGithub, SiGoogle } from "@icons-pack/react-simple-icons"
import { GradientBackground } from "@/components/gradient-background"
import { TypewriterVisual } from "@/components/typewriter-visual"
-const isProd = process.env.NEXT_PUBLIC_AUTH_MODE === "otp"
+const isProd = process.env.NODE_ENV === "production"
function OTPSignIn() {
const [email, setEmail] = useState("")
diff --git a/src/web/src/lib/auth.ts b/src/web/src/lib/auth.ts
index a0e9462dd..4164de4ba 100644
--- a/src/web/src/lib/auth.ts
+++ b/src/web/src/lib/auth.ts
@@ -2,7 +2,7 @@ import { betterAuth } from "better-auth"
import { emailOTP } from "better-auth/plugins"
import { getOtpSubject, renderOtpEmail } from "./email-templates"
-const isOtp = (env: Env) => env.AUTH_MODE === "otp"
+const isProd = process.env.NODE_ENV === "production"
export function createAuth(env: Env) {
return betterAuth({
@@ -10,7 +10,7 @@ export function createAuth(env: Env) {
database: env.DB,
secret: env.BETTER_AUTH_SECRET,
emailAndPassword: {
- enabled: !isOtp(env),
+ enabled: !isProd,
requireEmailVerification: false,
},
socialProviders: {
@@ -23,7 +23,7 @@ export function createAuth(env: Env) {
clientSecret: env.GOOGLE_CLIENT_SECRET,
},
},
- plugins: isOtp(env)
+ plugins: isProd
? [
emailOTP({
async sendVerificationOTP({ email, otp, type }) {
diff --git a/src/web/wrangler.toml b/src/web/wrangler.toml
index 7f0514860..6ccff7dfd 100644
--- a/src/web/wrangler.toml
+++ b/src/web/wrangler.toml
@@ -3,9 +3,6 @@ main = ".open-next/worker.js"
compatibility_date = "2026-04-09"
compatibility_flags = ["nodejs_compat"]
-[vars]
-AUTH_MODE = "otp"
-
# OpenNext required bindings
[assets]
directory = ".open-next/assets"