Repository navigation
Fail Vercel builds when native OAuth configuration is invalid - #272
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
masnwilliams
left a comment
There was a problem hiding this comment.
Looks good. Running the startup check as a build step stops a misconfigured deployment from promoting, and it follows the existing check:managed-auth-app pattern.
Two optional suggestions, neither blocking:
-
Import after the
VERCELcheck. Static imports run beforeif (!process.env.VERCEL) process.exit(0), so the script loadsnative-oauth→rediseven outside Vercel.redis.tsthrows at load time on invalid TLS settings, so a local build can still fail here (e.g.REDIS_TLS_SERVER_NAME=x REDIS_URL=redis://aexits 1). On Vercel that error also bypasses thetry/catch. Usingawait import(...)inside theVERCELbranch, asinstrumentation.tsdoes, makes "Local builds skip it" accurate. -
Share the log line with
instrumentation.ts. The two paths log different text for the same result (native OAuth enabledvsnative OAuth configuration ok,native OAuth disabledvsnative OAuth disabled for this deployment). A smalldescribeNativeOAuthConfig()innative-oauth.ts, called from both places, keeps them in sync. The script could then drop thetry/catch: an uncaught throw already exits 1 with the message and a stack trace.
export {};
if (process.env.VERCEL) {
const { describeNativeOAuthConfig } = await import("@/lib/native-oauth");
console.info(describeNativeOAuthConfig());
}
Summary
The native OAuth configuration check runs in
src/instrumentation.tswhen a server instance starts. On Vercel that happens after the deployment is built and promoted: a deployment with invalid settings still reachesREADY, takes over its domains, and then answers every route with a 500. The project has no deployment checks gating promotion.This runs the same
nativeOAuthConfig()check as a build step on Vercel (VERCELis set during Vercel builds). Invalid settings now fail the build, so the deployment never promotes and the previous one keeps serving. The startup check stays as is.scripts/check-native-oauth-config.ts: exits 0 outside Vercel; on Vercel, logs the resolved issuer/resource (or that native OAuth is off) and exits 1 with the configuration error otherwise.package.json:buildrunscheck:native-oauth-configafter the managed auth app check and beforenext build.Tests
Ran the script against the settings each environment uses:
VERCEL)API_BASE_URLAPI_BASE_URLfor another environmenthttps://mcp-preview.invalid)bunx tsc --noEmitpasses. The build log of this PR's preview deployment shows the preview case.