Conversation
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
Devin spotted a route error, and complains I do not return in the throw clause. I think that's a mistake; anyone calling this from a dev environment should fall through. It also will work if the variables are set in the environment otherwise. |
mdroidian
left a comment
There was a problem hiding this comment.
We need to throw if we don't have the vars. Also, some lint errors.
939c53d to
37f7362
Compare
| return NextResponse.json( | ||
| // eslint-disable-next-line @typescript-eslint/naming-convention | ||
| { SUPABASE_URL, SUPABASE_ANON_KEY }, | ||
| { status: 200 }, | ||
| ); |
There was a problem hiding this comment.
🟡 Missing CORS headers on GET response while OPTIONS handler has them
The new /api/supabase/env endpoint has inconsistent CORS handling. The OPTIONS handler uses defaultOptionsHandler which applies CORS headers, but the GET handler returns NextResponse.json() directly without applying CORS via the cors() function.
Root Cause
Other API endpoints in the codebase use createApiResponse() which internally calls cors(request, response) to add CORS headers (see apps/website/app/utils/supabase/apiUtils.ts:48). However, this new endpoint bypasses that pattern.
If this endpoint is ever called from a browser context (e.g., from the Roam extension at runtime), the browser would:
- Send OPTIONS preflight → receives CORS headers (allowed)
- Send actual GET request → receives response WITHOUT CORS headers
- Browser rejects the response due to missing
Access-Control-Allow-Origin
Currently this doesn't affect the build process since curl is used (packages/database/scripts/createEnv.mts:113), but it makes the API inconsistent and would break any future browser-based usage.
| return NextResponse.json( | |
| // eslint-disable-next-line @typescript-eslint/naming-convention | |
| { SUPABASE_URL, SUPABASE_ANON_KEY }, | |
| { status: 200 }, | |
| ); | |
| const response = NextResponse.json( | |
| // eslint-disable-next-line @typescript-eslint/naming-convention | |
| { SUPABASE_URL, SUPABASE_ANON_KEY }, | |
| { status: 200 }, | |
| ); | |
| return cors(request, response) as NextResponse; |
Was this helpful? React with 👍 or 👎 to provide feedback.
| return NextResponse.json( | ||
| // eslint-disable-next-line @typescript-eslint/naming-convention | ||
| { SUPABASE_URL, SUPABASE_ANON_KEY }, | ||
| { status: 200 }, | ||
| ); |
37f7362 to
a59b352
Compare
| writeFileSync( | ||
| join(projectRoot, ".env"), | ||
| Object.entries(asJson).map(([k,v])=>`${k}=${v}`).join('\n') | ||
| ); |
There was a problem hiding this comment.
🔴 Environment file written to wrong path - .env instead of .env.${variant} format
When ROAM_BUILD_SCRIPT=1 is set, createEnv.mts writes environment variables to packages/database/.env, but dbDotEnv.mjs:envFilePath() only reads files matching .env.${variant} pattern (like .env.local, .env.branch, .env.production).
Root Cause
The flow when ROAM_BUILD_SCRIPT=1:
createEnv.mts:115-118writes tojoin(projectRoot, ".env")- a plain.envfile- Later,
compile.ts:153callsenvContents()fromdbDotEnv.mjs dbDotEnv.mjs:64-68inenvFilePath()looks for.env.${variant}files only:const name = join(findRoot(), `.env.${variant}`); return existsSync(name) ? name : null;
- Since there's no
.env.${variant}file andprocess.envdoesn't have the variables,envContents()returns an empty object
Impact: The Roam build will not receive the SUPABASE_URL and SUPABASE_ANON_KEY values, causing the database connection to fail in the built extension. The fix should either write to .env.production (matching an existing variant) or add logic to read plain .env files.
| writeFileSync( | |
| join(projectRoot, ".env"), | |
| Object.entries(asJson).map(([k,v])=>`${k}=${v}`).join('\n') | |
| ); | |
| writeFileSync( | |
| join(projectRoot, ".env.production"), | |
| Object.entries(asJson).map(([k,v])=>`${k}=${v}`).join('\n') | |
| ); |
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
the base dotenv reads the content of .env in all cases.
https://linear.app/discourse-graphs/issue/ENG-1395/official-deployment-version-cannot-access-database
Access the vercel env values when building from the shell script.
https://www.loom.com/share/08dfa5be8386471d8b3caa4202f05d65