Merged in feat/env-in-functions (pull request #134)

feat: set NEXTAUTH_URL based on DEPLOY_PRIME_URL on Netlify

Approved-by: Simon.Emanuelsson
This commit is contained in:
Michael Zetterberg
2024-04-23 15:00:01 +00:00
committed by Simon.Emanuelsson
5 changed files with 24 additions and 7 deletions

View File

@@ -12,10 +12,11 @@ CURITY_CLIENT_ID_USER=""
CURITY_CLIENT_SECRET_USER=""
CURITY_ISSUER_USER="https://testlogin.scandichotels.com"
CYPRESS_BASE_URL="http://localhost:3000"
# See next.config.js for info
DEPLOY_PRIME_URL="http://localhost:3000"
DESIGN_SYSTEM_ACCESS_TOKEN=""
NEXTAUTH_REDIRECT_PROXY_URL="http://localhost:3000/api/web/auth"
NEXTAUTH_SECRET=""
NEXTAUTH_URL="http://localhost:3000/"
REVALIDATE_SECRET=""
SEAMLESS_LOGIN_DA="http://www.example.dk/updatelogin"
SEAMLESS_LOGIN_DE="http://www.example.de/updatelogin"

View File

@@ -45,7 +45,6 @@ const customProvider = {
} satisfies OIDCConfig<User>
export const config = {
basePath: "/api/web/auth",
providers: [customProvider],
redirectProxyUrl: env.NEXTAUTH_REDIRECT_PROXY_URL,
trustHost: true,

2
env/server.ts vendored
View File

@@ -25,7 +25,6 @@ export const env = createEnv({
DESIGN_SYSTEM_ACCESS_TOKEN: z.string(),
NEXTAUTH_REDIRECT_PROXY_URL: z.string().optional(),
NEXTAUTH_SECRET: z.string(),
NEXTAUTH_URL: z.string(),
NODE_ENV: z.enum(["development", "test", "production"]),
PRINT_QUERY: z.boolean().default(false),
REVALIDATE_SECRET: z.string(),
@@ -55,7 +54,6 @@ export const env = createEnv({
DESIGN_SYSTEM_ACCESS_TOKEN: process.env.DESIGN_SYSTEM_ACCESS_TOKEN,
NEXTAUTH_REDIRECT_PROXY_URL: process.env.NEXTAUTH_REDIRECT_PROXY_URL,
NEXTAUTH_SECRET: process.env.NEXTAUTH_SECRET,
NEXTAUTH_URL: process.env.NEXTAUTH_URL,
NODE_ENV: process.env.NODE_ENV,
PRINT_QUERY: process.env.PRINT_QUERY,
REVALIDATE_SECRET: process.env.REVALIDATE_SECRET,

View File

@@ -2,14 +2,20 @@
command = "npm run build"
publish = ".next"
[context.branch-deploy]
command = "npm run lint && npm run build"
[context.deploy-preview]
command = "npm run lint && npm run build"
[[plugins]]
package = "netlify-plugin-cypress"
[plugins.inputs]
configFile = "cypress.config.ts"
[plugins.inputs.postBuild]
enable = true
start = "npm start"
wait-on = "http://127.0.0.1:3000/en/test"
enable = true
start = "npm start"
wait-on = "http://127.0.0.1:3000/en/test"
wait-on-timeout = "30" # seconds
[build.environment]

View File

@@ -13,8 +13,21 @@ const jiti = createJiti(new URL(import.meta.url).pathname)
jiti("./env/server")
jiti("./env/client")
// We set NEXTAUTH_URL here because next.config.js is included in Netlify
// functions when bundling. Otherwise we are unable to login on preview
// deployments. We use DEPLOY_PRIME_URL from Netlify for all non-production
// branches. Locally we set it in .env.local instead of NEXTAUTH_URL.
// Netlify`s Next.js Runtime has built-in support for Next-Auth,
// but Next-Auth v5 is ESM and therefore not yet handle correctly by Netlify.
// This workaround should not be needed once Netlify fixes their code.
/** @type {import('next').NextConfig} */
const nextConfig = {
env: {
NEXTAUTH_URL:
(process.env.CONTEXT === "production"
? process.env.URL
: process.env.DEPLOY_PRIME_URL) + "/api/web/auth",
},
poweredByHeader: false,
eslint: { ignoreDuringBuilds: true },
images: {