Skip to content

Commit 94b726c

Browse files
committed
fix build isuses
1 parent 898c70b commit 94b726c

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

src/lib/auth.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,34 @@ import { betterAuth } from "better-auth";
22
import { genericOAuth } from "better-auth/plugins";
33

44
// Read from environment variables to support any OIDC provider
5-
const OIDC_ISSUER = process.env.OIDC_ISSUER_URL;
6-
const OIDC_CLIENT_ID = process.env.OIDC_CLIENT_ID;
7-
const OIDC_CLIENT_SECRET = process.env.OIDC_CLIENT_SECRET;
8-
const BETTER_AUTH_SECRET = process.env.BETTER_AUTH_SECRET;
5+
const OIDC_ISSUER = process.env.OIDC_ISSUER_URL || "";
6+
const OIDC_CLIENT_ID = process.env.OIDC_CLIENT_ID || "";
7+
const OIDC_CLIENT_SECRET = process.env.OIDC_CLIENT_SECRET || "";
8+
const BETTER_AUTH_SECRET =
9+
process.env.BETTER_AUTH_SECRET || "build-time-placeholder";
910
const BETTER_AUTH_URL = process.env.BETTER_AUTH_URL || "http://localhost:3000";
1011

11-
// Validate required environment variables
12-
if (!BETTER_AUTH_SECRET) {
13-
throw new Error(
14-
"[Better Auth] BETTER_AUTH_SECRET is required. Set it in .env.local to a strong, random value.",
15-
);
12+
// Validate required environment variables (warnings only during build)
13+
const isBuild = process.env.NEXT_PHASE === "phase-production-build";
14+
15+
if (!process.env.BETTER_AUTH_SECRET) {
16+
const message =
17+
"[Better Auth] BETTER_AUTH_SECRET is required. Set it in .env.local to a strong, random value.";
18+
if (isBuild) {
19+
console.warn(message);
20+
} else {
21+
throw new Error(message);
22+
}
1623
}
1724

1825
if (!OIDC_ISSUER || !OIDC_CLIENT_ID || !OIDC_CLIENT_SECRET) {
19-
throw new Error(
20-
"[Better Auth] OIDC configuration is incomplete. Set OIDC_ISSUER_URL, OIDC_CLIENT_ID, and OIDC_CLIENT_SECRET in .env.local",
21-
);
26+
const message =
27+
"[Better Auth] OIDC configuration is incomplete. Set OIDC_ISSUER_URL, OIDC_CLIENT_ID, and OIDC_CLIENT_SECRET in .env.local";
28+
if (isBuild) {
29+
console.warn(message);
30+
} else {
31+
throw new Error(message);
32+
}
2233
}
2334

2435
console.log("[Better Auth] OIDC Configuration:", {

0 commit comments

Comments
 (0)