chore(debug): envs in edge functions
This commit is contained in:
+14
-7
@@ -29,7 +29,9 @@
|
||||
* any other environment (branch deploys and deploy previews) we use the
|
||||
* predefined Netlify environment variable DEPLOY_PRIME_URL.
|
||||
*
|
||||
* NEXTAUTH_URL is set to point to the PUBLIC_URL.
|
||||
* Both AUTH_URL and NEXTAUTH_URL is set to point to the PUBLIC_URL.
|
||||
* We set both as a precaution as next-auth v5 is transitioning to AUTH_* but we
|
||||
* have seen several occurences in the auth.js codebase that are not using both.
|
||||
*/
|
||||
|
||||
import fs from "node:fs"
|
||||
@@ -50,15 +52,20 @@ if (process.env.NETLIFY) {
|
||||
PUBLIC_URL = process.env.DEPLOY_PRIME_URL
|
||||
}
|
||||
|
||||
const NEXTAUTH_URL = `${PUBLIC_URL}/api/web/auth`
|
||||
const AUTH_URL = `${PUBLIC_URL}/api/web/auth`
|
||||
const NEXTAUTH_URL = AUTH_URL
|
||||
|
||||
const replaceMap = {
|
||||
AUTH_URL,
|
||||
NEXTAUTH_URL,
|
||||
PUBLIC_URL,
|
||||
}
|
||||
|
||||
let contents = fs.readFileSync("./.env", { encoding: "utf-8" })
|
||||
|
||||
contents = contents.replace(/PUBLIC_URL=.*/, `PUBLIC_URL="${PUBLIC_URL}"`)
|
||||
contents = contents.replace(
|
||||
/NEXTAUTH_URL=.*/,
|
||||
`NEXTAUTH_URL="${NEXTAUTH_URL}"`
|
||||
)
|
||||
for (const [key, value] of Object.entries(replaceMap)) {
|
||||
contents = contents.replace(new RegExp(`${key}=.*`), `${key}="${value}"`)
|
||||
}
|
||||
|
||||
fs.writeFileSync("./.env", contents, { encoding: "utf-8" })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user